#!/bin/csh -f # script to generate (if not already existing) OpenSSH 2 keys # and push to remote host specified by argument one and optionally # the remote user specified by argument two # # Kevin P. Inscoe (kevin@inscoe.org) - December 5, 2002 # # Modified Jan. 27, 2003 to chmod AUTHFILE* to 700 # # Modified Sep. 2, 2005 to update both old and new style SSH2 authorized_keys # file now that authorized_keys is being widely used in SSH2 # # Check arguments if ( $#argv < 1 ) then echo "usage: pushkeys hostname (remote user)" exit 1 endif set REMHOST=$argv[1] if ( $#argv > 1 ) then set REMUSER=$argv[2] else set REMUSER=`/bin/id | /bin/awk -F\( '{ print $2 }' | /bin/awk -F\) '{ print $1 }'` endif # Globals set SSH_HOME=$HOME/.ssh set ID_DSA=$SSH_HOME/id_dsa set ID_DSA_PUB=$SSH_HOME/id_dsa.pub set ID_RSA=$SSH_HOME/id_rsa set ID_RSA_PUB=$SSH_HOME/id_rsa.pub set AUTHFILE1=".ssh/authorized_keys" set AUTHFILE2=".ssh/authorized_keys2" # generate the keys and use NULL passphrase if ( ! -e $ID_DSA ) then ssh-keygen -t dsa -f $ID_DSA -N "" endif if ( ! -e $ID_RSA ) then ssh-keygen -t rsa -f $ID_RSA -N "" endif # Copy the keys to the remote host /bin/cat $ID_DSA_PUB $ID_RSA_PUB | ssh -l $REMUSER $REMHOST "mkdir -p .ssh; chmod 700 .ssh; cat - >> $AUTHFILE1; chmod 700 $AUTHFILE1" /bin/cat $ID_DSA_PUB $ID_RSA_PUB | ssh -l $REMUSER $REMHOST "mkdir -p .ssh; chmod 700 .ssh; cat - >> $AUTHFILE2; chmod 700 $AUTHFILE2" # Test the connection ssh -l $REMUSER $REMHOST "echo 'Keys successfully copied'"