Skip to content

Instantly share code, notes, and snippets.

@quentinsf
Created May 18, 2012 11:12
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 quentinsf/2724723 to your computer and use it in GitHub Desktop.
Save quentinsf/2724723 to your computer and use it in GitHub Desktop.
sshput - copy an ssh id into the authorized keys on a remote machine
#!/bin/sh
# sshput <remotehost>
#
# Puts your local DSA public key into the .ssh/authorized_keys
# on a remote machine. This should allow you to login without
# needing a password.
#
# This software comes with no guarantees whatsoever, and is yours to
# do with as you will. I'd be grateful if you feed any generally-useful
# improvements back to me, for the benefit of others.
#
# Quentin Stafford-Fraser http://www.qandr.org/quentin
PUBKEY="${HOME}/.ssh/id_dsa.pub"
if [ $# -ne 1 -o "$1" = "-h" ]
then
echo
echo Syntax:
echo "$0 [user@]<remotehost>"
echo
exit 1
fi
if [ ! -r ${PUBKEY} ]
then
echo
echo Public key ${PUBKEY} not found.
echo You can generate this by running
echo " ssh-keygen -t dsa"
echo Then come back and run $0 again.
echo
exit 1
fi
echo If you are prompted for a password, enter your password on the
echo remote machine.
cat ${HOME}/.ssh/id_dsa.pub | \
ssh $1 'mkdir -p -m 0700 ${HOME}/.ssh && \
cat >> $HOME/.ssh/authorized_keys && \
chmod 0600 $HOME/.ssh/authorized_keys'
if [ $? -eq 0 ]
then
echo Public key installed on remote machine.
echo You should now be able to connect with
echo " ssh $1"
exit 0
else
echo Sorry, an error occurred!
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment