]> thyrsus.com Git - ssh-installkeys.git/commitdiff
Added -P option.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 21 Jun 2004 12:53:48 +0000 (12:53 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 21 Jun 2004 12:53:48 +0000 (12:53 +0000)
ssh-installkeys
ssh-installkeys.xml

index 9efbf66c19a918bcb3ad3d678fe189738b67ecab..02da3048fd72d03e31b54c8e532614aa900e36d9 100755 (executable)
@@ -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 <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
 
@@ -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)
index 000070aa42f14f02c63b6d9212d07f706a2e4107..69f721aa67068cd8da6b97aade6cedcfb25a3eab 100644 (file)
@@ -16,6 +16,7 @@
   <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>
@@ -49,6 +50,10 @@ a usage summary and exits.</para>
 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>