2010年11月26日 星期五

ssh-copy-id with port

$ cp /usr/bin/ssh-copy-id /usr/bin/ssh-copy-id.orig
$ vi /usr/bin/ssh-copy-id

#!/bin/sh

# Shell script to install your identity.pub on a remote machine
# 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.

ID_FILE="${HOME}/.ssh/identity.pub"

while getopts ':i:p:P:h' OPTION
do
    case $OPTION in
        i)
        if [ -n "$OPTARG" ]; then
            if expr "$OPTARG" : ".*.pub" > /dev/null ; then
                ID_FILE="$OPTARG"
            else
                ID_FILE="$OPTARG.pub"
            fi
        fi
        ;;
        P|p)
            PORT=$OPTARG;
        ;;
        h)
            echo "Usage: $0 [-i [identity_file]] [user@]machine" >&2
            exit 1
        ;;
    esac;
done;

shift $(($OPTIND - 1))

if [ $# -lt 1 ] && [ x$SSH_AUTH_SOCK != x ] ; then
   GET_ID="$GET_ID ssh-add -L"
fi

if [ -z "`eval $GET_ID`" ] && [ -r "${ID_FILE}" ] ; then
  GET_ID="cat ${ID_FILE}"
fi

if [ -z "`eval $GET_ID`" ]; then
  echo "$0: ERROR: No identities found" >&2
  exit 1
fi

if [ -z $PORT ]; then
    PORTOPTION=""
else
    PORTOPTION="-p $PORT "
fi;

{ eval "$GET_ID" ; } | ssh $PORTOPTION $1 "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys" || exit 1

cat <
Now try logging into the machine, with "ssh $PORTOPTION'$1'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

EOF

2 則留言:

  1. Server shows me "/usr/bin/ssh-copy-id: ERROR: No identities found"

    Do you know, what going is on?

    回覆刪除
  2. Maybe You have no file "~/.ssh/identity.pub".

    回覆刪除

DNSSEC安全技術簡介 作者:游子興 / 臺灣大學計算機及資訊網路中心網路組約聘幹事 DNS 是一套已經廣泛使用的Internet 服務,但因先天的技術限制導致容易成為駭客攻擊的目標。本文主要在介紹DNSSEC 之緣起與技術背景,及其使用的加解密技術如何確保資料的完整...