免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1554 | 回复: 0
打印 上一主题 下一主题

ssh-copy-id with port [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-30 14:32 |只看该作者 |倒序浏览

一个很有用的脚本,记录一下,具体用法不介绍了
cat 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 EOF
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
# ssh-copy-id -i ~/.ssh/id_rsa.pub "-p 22222
[email=user@server]user@server[/email]
"

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/10723/showart_2107351.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP