补充:autossh工具可以解决ssh断线重连的问题!
有一台内网windows计算机A,没有修改内网路由的权限,现在需要在任何地方可以远程桌面连接到此计算机。
有一台公网Linux服务器B。
实现:
A计算机通过SSH与B建立SSH隧道,B监听某个端口转发到A的某个端口。
A中cygwin下执行命令:
#!/bin/bash ssh -o ServerAliveInterval=180 -i /cygdrive/c/id_rsa root@B的外网IP -p 22 -R 33389:localhost:3389 -fN
这样连接B的33389端口就等于连接A的3389端口。
默认B的sshd只能监听127.0.0.1,需要修改配置项GatewayPorts yes才可监听外网,另外一个配置项默认应该是开启
AllowTcpForwarding yes
顺带还有一个本地端口转发的例子,并且自动重连
#!/bin/bash autossh -f -M 0 -o ServerAliveInterval=180 root@xx.xx.xx.xx -i "~/.ssh/id_rsa" -p 22 -L 9928:localhost:9928 -N
此功能完美,屌爆!
参考:
http://www.hi-roy.com/2016/05/20/linux系统的3种端口转发方式/
http://www.ruanyifeng.com/blog/2011/12/ssh_port_forwarding.html