有两种方式可以选择,包括 ProxyJump 和 ProxyCommand 。
ProxyJump 是通过端口转发的形式,需要跳板机支持端口转发。
ProxyCommand 是通过SSH协议转发
就安全性来说,ProxyJump是比较高的,因为他是端到端加密,跳板机是透传只做转发,可能性能也较好。
下面是两种方式的例子,其中包括了经过多个跳板机中转及使用证书登录的情况,Host1是已预置了本地用户的证书(这也是通常的方式),通过修改配置文件 .ssh/config 实现:
Host Host1
HostName 192.168.0.1
Port 22
User yourusername
Host Host2
HostName 192.168.0.2
Port 22
User yourusername
IdentityFile ~/xxx.pem
ProxyJump Host1
Host Host3
HostName 192.168.0.3
Port 22
User yourusername
IdentityFile ~/xxx.pem
ProxyJump Host2
Host Host1
HostName 192.168.0.1
Port 22
User yourusername
Host Host2
HostName 192.168.0.2
Port 22
User yourusername
IdentityFile ~/xxx.pem
ProxyCommand ssh Host1 -W %h:%p
Host Host3
HostName 192.168.0.3
Port 22
User yourusername
IdentityFile ~/xxx.pem
ProxyCommand ssh Host2 -W %h:%p