无跳板机

ssh $user@$target -p 1220 'mkdir -p .ssh && cat > .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

user是登录名,target是目标机器.第一次输好密码,后面就不用输了.

通过跳板机

  • 在~/.ssh/config中配置好别名

Host gateway
    HostName gateway url
    Port 1220
    IdentityFile ~/.ssh/id_rsa
    User xxx

Host target
    HostName target url
    User xxx
    IdentityFile ~/.ssh/id_rsa
    ProxyCommand ssh gateway nc %h %p 2> /dev/null
  • 执行命令

ssh target 'mkdir -p .ssh && cat > .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

和上面一样,也只需要第一次输入密码


TheViper
465 声望16 粉丝

引用和评论

0 条评论