Created
August 9, 2010 14:04
-
-
Save skreuzer/515456 to your computer and use it in GitHub Desktop.
Push ssh keys to a new host
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/sh | |
# Check if an argument was given. | |
if [ ! "${1}" ] ; then | |
echo "No hostname provided" > /dev/stderr | |
exit 1 | |
fi | |
if [ ! "${2}" ]; then | |
KEYFILE=~/.ssh/id_rsa.pub | |
else | |
KEYFILE=${2} | |
fi | |
if [ ! -f ${KEYFILE} ] ; then | |
echo "${KEYFILE} does not exist" > /dev/stderr | |
exit 1 | |
fi | |
cat ${KEYFILE} | ssh -q "${1}" i\ | |
" \ | |
if [ ! -d ~/.ssh/ ] ; \ | |
then \ | |
mkdir ~/.ssh ; \ | |
fi ; \ | |
chmod 700 ~/.ssh/ ; \ | |
cat - >> ~/.ssh/authorized_keys ; \ | |
chmod 600 ~/.ssh/authorized_keys \ | |
" | |
exit $? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment