ssh从A到C通过B框使用A键而不将其存储在B机器上

时间:2016-04-08 13:56:28

标签: linux ssh ssh-tunnel

我正在编写脚本,只使用一个键从A到B连接到C机器。

所以我想做这样的事情:

ssh -t -i id_rsa user@b_box ssh -i id_rsa user@c_box

问题是我只想在我的localhost上存储id_rsa。有没有办法将此密钥作为参数或变量传递给B机器,这样我可以连接到没有密码的C盒?

我希望能够从B机器无密码登录超过30个盒子(将来可能更多)。当我将我的钥匙存放在B盒上时,这很容易。

1 个答案:

答案 0 :(得分:2)

这是我们ProxyCommand的目的:

ssh -i id_rsa -oProxyCommand="ssh -W %h:%p user@b_box" user@c_box

或者更确切地说是~/.ssh/config

Host b_box
  User user
  IdentityFile /path/to/id_rsa
Host c_box
  ProxyCommand ssh -W %h:%p b_box
  User user
  IdentityFile /path/to/id_rsa

然后只与ssh c_box连接。