From: Eric S. Raymond Date: Mon, 21 Jun 2004 12:53:48 +0000 (+0000) Subject: Added -P option. X-Git-Tag: 1-4 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=cd1b9743b0304ce6a4a43e5618351810347aed24;p=ssh-installkeys.git Added -P option. --- diff --git a/ssh-installkeys b/ssh-installkeys index 9efbf66..02da304 100755 --- a/ssh-installkeys +++ b/ssh-installkeys @@ -11,10 +11,11 @@ Options: -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 Connect on a particular port in place of 22 Author: Eric S. Raymond """ -# $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 @@ -63,7 +64,7 @@ A critical module was not found. Probably this OS does not support it. 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__'] @@ -565,11 +566,12 @@ def split_command_line(command_line): 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) @@ -593,9 +595,9 @@ class ssh_session: 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) @@ -641,16 +643,19 @@ def forcefile(session, file, command, checkonly=None): 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 @@ -729,7 +734,7 @@ if __name__ == '__main__': # 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) diff --git a/ssh-installkeys.xml b/ssh-installkeys.xml index 000070a..69f721a 100644 --- a/ssh-installkeys.xml +++ b/ssh-installkeys.xml @@ -16,6 +16,7 @@ ssh-installkeys -h -c + -p port -d -v name@host @@ -49,6 +50,10 @@ a usage summary and exits. your local and remote ssh configuration for problems without changing anything. +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. + Invoked with the option, the program deletes any public keys under the specified login at the specified host.