ssh 通过代理机跳转内网
(1)ssh使用跳转
$ ssh -J user@jump-host:port <user@remote:port>
(2)proxyjump
vscode使用proxyjump时,连接中转服务器后报错:
channel 0: open failed: administratively prohibited: open failed
stdio forwarding failed
kex_exchange_identification: Connection closed by remote host
解决方法1:(成功)
Host customer
Hostname customer.whatever.com <–跳板主板主机要能正确解析hostname才行,否则请填IP
User linuxuser
ForwardAgent
yes Port 22
ProxyCommand ssh user1@jump.linux.com -p 5566 nc %h %p
(ref:
https://shazi.info/%E5%88%A9%E7%94%A8ssh-proxycommand%E5%8F%8Anc%E5%81%9A%E8%B7%B3%E6%9D%BF%E7%9A%84%E9%80%A3%E7%B7%9A%E6%87%89%E7%94%A8/)
解决方法2:(该解决方法不知是否可行)
/etc/ssh/sshd_config
AllowTcpForwarding yes
(但是没有root权限无法操作)
(3)proxycommand使用例子
Host tiaoban
Hostname 跳板机的ip
Port 跳板机的端口(如果是非22的需要填写)
User root(如果非root,换成跳板机的用户)
Host mubiaoji
Hostname 目标机的IP
Port 跳板机的端口(如果是非22的需要填写)
User root(如果非root,换成跳板机的用户)
ProxyCommand ssh -q -x -W %h:%p tiaoban (该方法使用报错:kex_exchange_identification: Connection closed by remote host)
(成功的方法请参考上边成功的方法)
这儿的%h表示要连接的目标机,也就是Hostname指定的ip或者主机名,%p表示要连接到目标机的端口.这儿可以直接写死固定值,但是使用%h和%p可以保证在Hostname和Port变化的情况下ProxyCommand这行不用跟着变化.