今天在和SA处理新环境的时候,被鄙视了一顿,因为是通过一台跳转始终无法跳到最终的目的机器,他始终就给我来一个词:forwarding!!!我表示,我直接将key也copy过去的,最后没办法,过去被鄙视了一顿,加个-A的确就好了,后来才发现,我copy的key不是对应应该forwarding,不过这还是自己的问题,思维不够敏捷
我想登陆到测试机VM2上,必须要经过一个跳转机VM1,才能跳转到VM2
我当时的做法
首先将要forwarding的private key添加一下
$ ssh-add ~/.ssh/id_rsa Identity added: /Users/lihui/.ssh/id_rsa (/Users/lihui/.ssh/id_rsa)
然后偏偏登陆跳转机的时候,忘了加-A,所以跳转机是能够登陆的
$ ssh lihui@vm1
最后登陆vm2的时候,就会一直报
Pubkey Unauthorization.
所以我就直接想将前面登陆跳转机的私钥copy过来,再登陆,偏偏copy的私钥copy错了,导致出了问题
其实Forwarding起来很直接,它的目的就是让本地的key转发到跳转上,使得在跳转机上也能够使用,这样就省去了copy,也比较安全
首先跟上面一样,将private key添加一下
$ ssh-add ~/.ssh/id_rsa Identity added: /Users/lihui/.ssh/id_rsa (/Users/lihui/.ssh/id_rsa)
既然都已经添加了,就不要想着后面还去copy私钥了,直接登陆跳转机带上-A选项
$ ssh -A lihui@vm1
此时key已经转过来了,直接再登陆vm2即可
$ ssh lihui@vm2
这就是整个流程,假如想将登陆vm1的过程,配置到config文件中,这里需要带上转发key
Host $SSH_NAME HostName $IPADDR Port $PORT User $USER ForwardAgent yes
加上最后一行即可
最后是man page里-A的说明
-A Enables forwarding of the authentication agent connection. This can also be specified on a per-host basis in a configuration file. Agent forwarding should be enabled with caution. Users with the ability to bypass file permissions on the remote host (for the agent's UNIX-domain socket) can access the local agent through the forwarded connection. An attacker cannot obtain key material from the agent, however they can perform operations on the keys that enable them to authenticate using the identities loaded into the agent.