Skip to content

Instantly share code, notes, and snippets.

@xsyn
Created December 3, 2012 08:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xsyn/4193705 to your computer and use it in GitHub Desktop.
Save xsyn/4193705 to your computer and use it in GitHub Desktop.
add-my-key.sh
#!/bin/bash
if [ $# -lt 1 ]
then
echo "Usage: ${0##*/} user@host"
echo " Adds your id_rsa.pub to the desitnation authorized_keys2 file"
exit 1
fi
if [ ! -f ~/.ssh/id_rsa.pub ]
then
echo "~/.ssh/id_rsa.pub not found, trying to generate"
ssh-keygen -t rsa
if [ ! -f ~/.ssh/id_rsa.pub ]
then
echo "Failed"
exit 1
fi
fi
cat ~/.ssh/id_rsa.pub | ssh $* "mkdir -p .ssh; chmod 700 .ssh;cat >> .ssh/tmp; cat .ssh/tmp >> .ssh/authorized_keys; cat .ssh/tmp >> .ssh/authorized_keys2; chmod 600 .ssh/authorized_keys2 .ssh/authorized_keys"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment