【问题标题】:ssh from A to C via B box using A key without storing it on B machine [closed]使用A密钥通过B框从A到C的ssh而不将其存储在B机器上[关闭]
【发布时间】:2016-07-29 19:53:52
【问题描述】:

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

所以我想做这样的事情:

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

问题是我只想将 id_rsa 存储在我的本地主机上。有没有什么办法可以把这个key作为参数或者变量传给B机器,这样我就可以不用密码连接到C盒子了?

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

【问题讨论】:

    标签: linux ssh ssh-tunnel


    【解决方案1】:

    这就是我们 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

    【讨论】:

    • 效果很好。感谢帮助!现在我只需要创建脚本来用我的服务器列表填充配置!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-01
    • 1970-01-01
    • 2017-01-05
    • 2014-02-11
    • 2022-06-14
    • 2020-12-25
    • 1970-01-01
    相关资源
    最近更新 更多