Handy Script for Pushing SSH Keys

The pussh.sh script automatically pushes your SSH private key to the server specified so you can have automatic SSH,scp and sftp authentication. If you don't have a key the script will generate one for you, also this script assumes that the user running the script has a home directory on the remote host. Should note that this script will only push the RSA encrypted key. SSH Automatic login is further described in the document SSH Hardening and Authorized Keys.

The Script

# say: ./pussh.sh hostname
# Uploads your id_rsa.pub to the specified host, wrapped for readability
if [ ! -r ${HOME}/.ssh/id_rsa.pub ]; then
 ssh-keygen -b 2048 -t rsa
# Append to the copy on the remote server
cat ~/.ssh/id_rsa.pub | ssh ${USER}@$1 "cat - >> .ssh/authorized_keys"

if [ $? -eq 0 ]; then
  echo "Success"

Loading Comments from Disqus...