Created
December 3, 2012 08:47
-
-
Save xsyn/4193705 to your computer and use it in GitHub Desktop.
add-my-key.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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