#!/usr/bin/env python
"""ssh-installkeys -- prepare a remote account for ssh access
-This script tries to export ssh public keys to a specified site. it will
+This script tries to export ssh public keys to a specified site. It will
walk you through generating key pairs if it doesn't find any to export.
It handles all the fiddly details like making sure local and remote
permissions are correct, and tells you what it's doing if it has to change
Options:
-h Print usage summary and exit
--l login Specify login name to be used at the remote site (default '%s')
-c Check local and remote configuration only, don't try to fix problems.
-d Delete remote .ssh configuration.
-v Report all commands sent to host and output received.
Author: Eric S. Raymond <esr@thyrsus.com>
-$Id: ssh-installkeys,v 1.12 2003/12/03 22:58:22 esr Exp esr $
+$Id: ssh-installkeys,v 1.13 2003/12/04 00:44:45 esr Exp esr $
"""
import os, sys, getopt, string, getpass, tempfile
###############################################################################
#
# pexpect 0.94 is inlined here because it's not in the Python library yet.
-# Some comments have been removed, and the interact() method.
+# Some comments and trivial unused methods have been removed.
#
"""
http://www.opensource.org/licenses/PythonSoftFoundation.html
Noah Spurrier
-
-$Revision: 1.12 $
-$Date: 2003/12/03 22:58:22 $
"""
import os, sys
import select
Currently pexpect is intended for UNIX operating systems (including OS-X)."""
__version__ = '0.94'
-__revision__ = '$Revision: 1.12 $'
+__revision__ = '$Revision: 1.13 $'
__all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn',
'__version__', '__revision__']
self.timeout = timeout
self.child_fd = -1
self.pid = None
- self.log_file = None
self.before = None
self.after = None
self.match = None
new[3] = new[3] & ~termios.ECHO # lflags
termios.tcsetattr(self.child_fd, termios.TCSADRAIN, new)
- def setlog (self, fileobject):
- """This sets logging output to go to the given fileobject.
- Set fileobject to None to stop logging.
- """
- self.log_file = fileobject
-
def compile_pattern_list(self, pattern):
"""This compiles a pattern-string or a list of pattern-strings.
This is used by expect() when calling expect_list().
It includes a timeout. If the read does not complete within the
timeout period then a TIMEOUT exception is raised.
If the end of file is read then an EOF exception will be raised.
- If a log file was set using setlog() then all data will
- also be written to the log file.
Notice that if this method is called with timeout=None
then it actually may block.
self.flag_eof = 1
raise EOF('End Of File (EOF) in read(). Empty string style platform.')
- if self.log_file != None:
- self.log_file.write (s)
- self.log_file.flush()
-
return s
raise ExceptionPexpect('Reached an unexpected state in read().')
- def write(self, text):
- """This is an alias for send().
- This return the number of bytes actually written.
- """
- return self.send (text)
-
- def writelines (self, sequence):
- """This calls write() for each element in the sequence.
- This return the number of bytes actually written.
- """
- total_n = 0
- for str in sequence:
- total_n = total_n + self.write (str)
- return total_n
-
def send(self, text):
"""This sends a string to the child process.
This return the number of bytes actually written.
if __name__ == '__main__':
# Process options
- (options, arguments) = getopt.getopt(sys.argv[1:], "cdhl:v")
- optlogin = None
+ (options, arguments) = getopt.getopt(sys.argv[1:], "cdh:v")
check = 0
verbose = 0
delete = 0
- print options
-
for (switch, val) in options:
if (switch == '-c'):
check = 1
elif (switch == '-h'):
print __doc__ % login
raise SystemExit, 0
- elif (switch == '-l'):
- optlogin = val
elif (switch == '-v'):
verbose = 1
else:
host = arguments[0]
if "@" in host:
- (atlogin, host) = string.split(host, "@")
- login = optlogin or atlogin \
- or os.environ.get("USER") or os.environ.get("LOGNAME")
+ (login, host) = string.split(host, "@")
+ else:
+ login = os.environ.get("LOGNAME") or os.environ.get("USER")
# Verify that key pairs are present on the local side
print "Checking your local configuration..."