比较简单的设置,就是利用 sshconfig 。

3、如果服务器需要通过跳板机登录(跳板机需要走本地网络代理)

首先配置跳板机ssh

Host jumper
HostName yyy.yyy.yyy.yyy # 跳板机IP,跳板机~/.ssh/authorized_keys需要配置ssh公钥
User root
ForwardAgent yes
IdentityFile /Users/aslinwang/.ssh/id_ecdsa
ProxyCommand corkscrew 127.0.0.1 12679 %h %p
然后通过跳板机访问服务器

Host aslin
HostName xxx.xxx.xxx.xxx # 远程服务器IP,~/.ssh/authorized_keys需要配置ssh公钥
User root
ForwardAgent yes
IdentityFile /Users/aslinwang/.ssh/id_ecdsa
ProxyCommand ssh jumper -W %h:%p 2> /dev/null
如果你不用 公钥,那可以尝试用sshpass (即,输密码式的登录):
Host aslin
HostName xxx.xxx.xxx.xxx # 远程服务器IP,~/.ssh/authorized_keys需要配置ssh公钥
User root
ForwardAgent yes
IdentityFile /Users/aslinwang/.ssh/id_ecdsa
ProxyCommand sshpass -p [跳板机密码] ssh -p [跳板机端口] root@[跳板机IP] -W %h:%p 2> /dev/null
------EOF----
文中的aslinwang是上述网址文章中的用户,如果是你自己的,就是/Users/用户名/,相信能找到这里的人应该都明白