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