-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.
+-p <port> Connect on a particular port in place of 22
Author: Eric S. Raymond <esr@thyrsus.com>"""
-# $Id: ssh-installkeys,v 1.16 2004/01/08 05:47:07 esr Exp esr $
+# $Id: ssh-installkeys,v 1.17 2004/03/11 23:19:16 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.16 $'
+__revision__ = '$Revision: 1.17 $'
__all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn',
'__version__', '__revision__']
class ssh_session:
"Session with extra state including the password to be used."
- def __init__(self, user, host, password=None, verbose=0):
+ def __init__(self, user, port, host, password=None, verbose=0):
self.user = user
self.host = host
self.verbose = verbose
self.password = password
+ self.port = port
def __exec(self, command):
"Execute a command on the remote host. Return the output."
child = spawn(command)
child.sendline("yes")
return child.before
def ssh(self, command):
- return self.__exec("ssh -l %s %s \"%s\""%(self.user,self.host,command))
+ return self.__exec("ssh -p %s -l %s %s \"%s\""%(session.port, self.user,self.host,command))
def scp(self, src, dst):
- return self.__exec("scp %s %s@%s:%s" % (src, session.user, session.host, dst))
+ return self.__exec("scp -P %s %s %s@%s:%s" % (session.port, src, session.user, session.host, dst))
def exists(self, file):
"Retrieve file permissions of specified remote file."
seen = self.ssh("/bin/ls -ld %s" % file)
if __name__ == '__main__':
# Process options
- (options, arguments) = getopt.getopt(sys.argv[1:], "cdhv")
+ (options, arguments) = getopt.getopt(sys.argv[1:], "cdhv:p:")
check = 0
verbose = 0
delete = 0
+ port = 22
for (switch, val) in options:
if (switch == '-c'):
check = 1
elif (switch == '-d'):
delete = 1
+ elif (switch == '-p'):
+ port = val;
elif (switch == '-h'):
print __doc__
raise SystemExit, 0
# Get session to remote host.
print "Starting session to %s..." % host
- session = ssh_session(login, host, verbose=verbose)
+ session = ssh_session(login, port, host, verbose=verbose)
# Permissions checks
fixperms(session, "~", check)
<command>ssh-installkeys</command>
<arg choice='opt'>-h</arg>
<arg choice='opt'>-c</arg>
+ <arg choice='opt'>-p <replaceable>port</replaceable></arg>
<arg choice='opt'>-d</arg>
<arg choice='opt'>-v</arg>
<arg choice='plain' rep='repeat'><replaceable>name@host</replaceable></arg>
your local and remote ssh configuration for problems without changing
anything.</para>
+<para>The -p option allows you to set a port number, overriding the
+default 22. This may be useful if you have a firewall and port
+forwarding setup.</para>
+
<para>Invoked with the <option>-d</option> option, the program deletes
any public keys under the specified login at the specified host.</para>