Author: Eric S. Raymond <esr@thyrsus.com>"""
-# $Id: ssh-installkeys,v 1.15 2003/12/30 17:15:58 esr Exp esr $
+# $Id: ssh-installkeys,v 1.16 2004/01/08 05:47:07 esr Exp esr $
import os, sys, getopt, string, getpass, tempfile
Currently pexpect is intended for UNIX operating systems (including OS-X)."""
__version__ = '0.94'
-__revision__ = '$Revision: 1.15 $'
+__revision__ = '$Revision: 1.16 $'
__all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn',
'__version__', '__revision__']
sys.stderr.write("-> " + command + "\n")
while True:
seen=child.expect([EOF,'assword:','continue connecting (yes/no)?'])
+ if self.verbose:
+ sys.stderr.write("<- " + child.before + "\n")
if seen == 0:
break
elif seen == 1:
+ if self.verbose:
+ sys.stderr.write("Saw password prompt...\n")
if not self.password:
self.password = getpass.getpass('Remote password: ')
child.sendline(self.password)
- seen = child.expect(EOF)
elif seen == 2:
+ if self.verbose:
+ sys.stderr.write("Saw 'continue connecting' prompt...\n")
child.sendline("yes")
- if self.verbose:
- sys.stderr.write("<- " + child.before + "\n")
return child.before
def ssh(self, command):
return self.__exec("ssh -l %s %s \"%s\""%(self.user,self.host,command))
def exists(self, file):
"Retrieve file permissions of specified remote file."
seen = self.ssh("/bin/ls -ld %s" % file)
+ if self.verbose:
+ sys.stderr.write("Existence check on %s gave %s\n" % (file,`seen`))
if string.find(seen, "No such file") > -1:
return None # File doesn't exist
else:
if not arguments:
print "No remote host specified."
- print __doc__ % login
+ print __doc__
raise SystemExit, 0
else:
host = arguments[0]
die("Try re-running this script without the check-only option.")
public_keys = []
for (keytype, file) in (("rsa1", "identity"), ("dsa", "id_dsa")):
- print "About to generate a %s key. You will be prompted for a passphrase,"
+ print "About to generate a %s key. You will be prompted for a passphrase," % keytype
print "Pressing enter at that prompt will create a key with no passphrase"
os.system("ssh-keygen -t %s -f %s" % (keytype, file))
public_keys.append(file + ".pub")