Skip to content

Instantly share code, notes, and snippets.

@skreuzer
Created August 9, 2010 14:04
Show Gist options
  • Save skreuzer/515456 to your computer and use it in GitHub Desktop.
Save skreuzer/515456 to your computer and use it in GitHub Desktop.
Push ssh keys to a new host
#!/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