Created
January 1, 2011 16:55
-
-
Save jfro/761845 to your computer and use it in GitHub Desktop.
modified someone's sshput command for uploading ssh public keys
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
sshput () { | |
RSAKEY="${HOME}/.ssh/id_rsa.pub" | |
DSAKEY="${HOME}/.ssh/id_dsa.pub" | |
if [ $# -eq 2 ]; then | |
KEY=$1 | |
if [ ! -r $KEY ] | |
then | |
echo "'$KEY' does not exist or is not readable" | |
return 1 | |
fi | |
SERVER=$2 | |
else | |
if [ -r ${RSAKEY} ]; then | |
KEY=$RSAKEY | |
elif [ -r ${DSAKEY} ]; then | |
KEY=$RSAKEY | |
else | |
echo "No RSA or DSA key found" | |
return 1 | |
fi | |
SERVER=$1 | |
fi | |
if [ $# -lt 1 -o "$1" = "-h" ]; then | |
echo Syntax: | |
echo "$0 [publickey] [user@]<remotehost>" | |
return 1 | |
fi | |
# testing above | |
echo "Copying $KEY to $SERVER" | |
cat $KEY | \ | |
ssh $SERVER '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 $SERVER" | |
return 0 | |
else | |
echo "Sorry, an error occurred!" | |
return 1 | |
fi | |
} |
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 | |
# sshput [publickey] [user@]<remotehost> | |
# | |
# modified by Jeremy Knope <[email protected]> for optional key specification & automatic rsa/dsa attempts | |
# | |
# Puts your local RSA/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 | |
RSAKEY="${HOME}/.ssh/id_rsa.pub" | |
DSAKEY="${HOME}/.ssh/id_dsa.pub" | |
if [ $# -eq 2 ] | |
then | |
KEY=$1 | |
if [ ! -r $KEY ] | |
then | |
echo "'$KEY' does not exist or is not readable" | |
exit 1 | |
fi | |
SERVER=$2 | |
else | |
if [ -r ${RSAKEY} ] | |
then | |
KEY=$RSAKEY | |
elif [ -r ${DSAKEY} ] | |
then | |
KEY=$RSAKEY | |
else | |
echo "No RSA or DSA key found" | |
exit 1 | |
fi | |
SERVER=$1 | |
fi | |
if [ $# -lt 1 -o "$1" = "-h" ] | |
then | |
echo Syntax: | |
echo "$0 [publickey] [user@]<remotehost>" | |
exit 1 | |
fi | |
# testing above | |
echo "Copying $KEY to $SERVER" | |
cat $KEY | \ | |
ssh $SERVER '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 $SERVER" | |
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