ssh-ProxyCommand免密码

假设自己的电脑是A,跳板机是B,要访问的机器是C。首先在A上生成ssh密钥,然后把公钥放到B和C上。然后在A机器上的.ssh/config里进行如下配置:

Host B
        HostName 在A视角下B的IP
        Port 在A视角下B的端口
        User B上的用户名
        IdentityFile 本地的ssh私钥路径

Host C
        ProxyCommand ssh -W 在B视角下C的IP:在B视角下C的端口 B
        User C上的用户名
        IdentityFile 本地的ssh私钥路径

然后在A机器上直接ssh C即可免密码登录C。

如果是IPv6,要这样:

Host D
        HostName 在B视角下的IPv6地址
        ProxyCommand ssh -W "[%h]":在B视角下的端口 B
        User D上的用户名
        IdentityFile 本地的ssh私钥路径

参考:

内网穿透

https://serverfault.com/questions/906298/ssh-proxycommand-with-same-password

https://superuser.com/questions/1674913/how-to-configure-proxycommand-in-ssh-config-in-macos-to-support-ipv6

posted @ 2024-09-28 13:42  寻找繁星  阅读(5)  评论(0编辑  收藏  举报