ssh-copy-id revision 189006
1122780Salc#!/bin/sh 2122780Salc 3122780Salc# Shell script to install your public key on a remote machine 4122780Salc# Takes the remote machine name as an argument. 5122780Salc# Obviously, the remote machine must accept password authentication, 6122780Salc# or one of the other keys in your ssh-agent, for this to work. 7122780Salc 8122780SalcID_FILE="${HOME}/.ssh/id_rsa.pub" 9122780Salc 10122780Salcif [ "-i" = "$1" ]; then 11122780Salc shift 12122780Salc # check if we have 2 parameters left, if so the first is the new ID file 13122780Salc if [ -n "$2" ]; then 14122780Salc if expr "$1" : ".*\.pub" > /dev/null ; then 15122780Salc ID_FILE="$1" 16122780Salc else 17122780Salc ID_FILE="$1.pub" 18122780Salc fi 19122780Salc shift # and this should leave $1 as the target name 20122780Salc fi 21122780Salcelse 22122780Salc if [ x$SSH_AUTH_SOCK != x ] ; then 23122780Salc GET_ID="$GET_ID ssh-add -L" 24122780Salc fi 25122780Salcfi 26122780Salc 27122780Salcif [ -z "`eval $GET_ID`" ] && [ -r "${ID_FILE}" ] ; then 28122780Salc GET_ID="cat ${ID_FILE}" 29122780Salcfi 30122780Salc 31122780Salcif [ -z "`eval $GET_ID`" ]; then 32122780Salc echo "$0: ERROR: No identities found" >&2 33122780Salc exit 1 34122780Salcfi 35122780Salc 36128393Salcif [ "$#" -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then 37128393Salc echo "Usage: $0 [-i [identity_file]] [user@]machine" >&2 38128393Salc exit 1 39128393Salcfi 40128393Salc 41128393Salc{ eval "$GET_ID" ; } | ssh $1 "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys" || exit 1 42128393Salc 43122780Salccat <<EOF 44255289SglebiusNow try logging into the machine, with "ssh '$1'", and check in: 45255289Sglebius 46255289Sglebius .ssh/authorized_keys 47255289Sglebius 48255289Sglebiusto make sure we haven't added extra keys that you weren't expecting. 49255289Sglebius 50255289SglebiusEOF 51255289Sglebius