我使用ssh -L -g
,但连接间歇性丢失,因此:
$ ssh -L 8080:localhost:8080 example.com -g
Last login: Tue Apr 24 07:19:04 2012 from 203.0.113.123
Read from remote host example.com: Connection timed out
Connection to example.com closed.
Run Code Online (Sandbox Code Playgroud)
任何人都可以提出一种强大的方法来保持这些连接的活动,并在它们关闭时重新连接它。
autossh is a program to start a copy of ssh and monitor it,
restarting it as necessary should it die or stop passing traffic.
Run Code Online (Sandbox Code Playgroud)
替换问题中给出的参数:
autossh -M 0 -L 8080:localhost:8080 example.com -g
Run Code Online (Sandbox Code Playgroud)
(-M 0
需要转动monitoring loop off
)
我能够通过以下方式自动重新建立kill -9
连接:example.com
autossh
local$ autossh -M 0 -L 8080:localhost:8080 example.com -g
Last login: Wed Apr 25 03:23:56 2012 from 203.0.113.123
example.com$
Run Code Online (Sandbox Code Playgroud)
kill -9
在 上的连接的 PID 上执行example.com
。
local$ Connection to example.com closed.
Last login: Wed Apr 25 03:34:01 2012 from 203.0.113.123
local$
Run Code Online (Sandbox Code Playgroud)