2000-03-15 01:13:01 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2009-01-21 09:29:20 +00:00
|
|
|
# Shell script to install your public key on a remote machine
|
2000-03-15 01:13:01 +00:00
|
|
|
# Takes the remote machine name as an argument.
|
|
|
|
# Obviously, the remote machine must accept password authentication,
|
|
|
|
# or one of the other keys in your ssh-agent, for this to work.
|
|
|
|
|
2009-01-21 09:29:20 +00:00
|
|
|
ID_FILE="${HOME}/.ssh/id_rsa.pub"
|
2000-03-15 01:13:01 +00:00
|
|
|
|
|
|
|
if [ "-i" = "$1" ]; then
|
|
|
|
shift
|
|
|
|
# check if we have 2 parameters left, if so the first is the new ID file
|
|
|
|
if [ -n "$2" ]; then
|
2008-01-19 18:52:04 +00:00
|
|
|
if expr "$1" : ".*\.pub" > /dev/null ; then
|
2000-03-15 01:13:01 +00:00
|
|
|
ID_FILE="$1"
|
|
|
|
else
|
|
|
|
ID_FILE="$1.pub"
|
|
|
|
fi
|
|
|
|
shift # and this should leave $1 as the target name
|
|
|
|
fi
|
|
|
|
else
|
2010-03-26 00:18:27 +00:00
|
|
|
if [ x$SSH_AUTH_SOCK != x ] && ssh-add -L >/dev/null 2>&1; then
|
2000-03-15 01:13:01 +00:00
|
|
|
GET_ID="$GET_ID ssh-add -L"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2004-08-30 11:33:02 +00:00
|
|
|
if [ -z "`eval $GET_ID`" ] && [ -r "${ID_FILE}" ] ; then
|
2011-08-17 02:01:44 +00:00
|
|
|
GET_ID="cat \"${ID_FILE}\""
|
2000-03-15 01:13:01 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "`eval $GET_ID`" ]; then
|
2003-01-03 03:34:06 +00:00
|
|
|
echo "$0: ERROR: No identities found" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$#" -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
|
|
|
echo "Usage: $0 [-i [identity_file]] [user@]machine" >&2
|
2000-03-15 01:13:01 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2010-08-10 03:36:09 +00:00
|
|
|
# strip any trailing colon
|
|
|
|
host=`echo $1 | sed 's/:$//'`
|
|
|
|
|
|
|
|
{ eval "$GET_ID" ; } | ssh $host "umask 077; test -d ~/.ssh || mkdir ~/.ssh ; cat >> ~/.ssh/authorized_keys" || exit 1
|
2000-03-15 01:13:01 +00:00
|
|
|
|
|
|
|
cat <<EOF
|
2010-08-10 03:36:09 +00:00
|
|
|
Now try logging into the machine, with "ssh '$host'", and check in:
|
2000-03-15 01:13:01 +00:00
|
|
|
|
2010-06-18 01:09:24 +00:00
|
|
|
~/.ssh/authorized_keys
|
2000-03-15 01:13:01 +00:00
|
|
|
|
|
|
|
to make sure we haven't added extra keys that you weren't expecting.
|
|
|
|
|
|
|
|
EOF
|
2010-06-18 01:09:24 +00:00
|
|
|
|