#!/bin/sh # setup_sshkey.sh # Appends your ssh public key to a remote host's authorized key file # and make's sure some permissions are correct # so you can login without typing the remote password each time # # Also generates your local private key if none exists # # Any ssh options will be passed on to ssh # # Best way to install it is to put it in /usr/local/bin under the name setup_ssh # This way users can simply prepend setup_ to the ssh command that they want to work without typing a password if [ -z "$1" ] ; then echo Setup passwordless ssh access echo EXAMPLES: echo $0 user@example.com "(Setup passwordless access to user@example.com)" echo $0 -p 2000 user@example.com "(Same as above, if ssh is on port 2000)" else [ ! -e ~/.ssh/id_dsa.pub ] && echo No existing ssh dsa key. Creating one now. && ssh-keygen -t dsa -f ~/.ssh/id_dsa -N '' cat ~/.ssh/id_dsa.pub | ssh $@ 'mkdir -p ~/.ssh; chmod 700 ~/.ssh; cat - >> ~/.ssh/authorized_keys2; chmod 644 ~/.ssh/authorized_keys2' fi