我在多个不可靠的互联网连接后面有一个 ssh 客户端机器picard - 全部使用 NAT。
我有我的服务器时间,可靠的静态 IP。我希望能够访问皮卡德thorugh时间。我以前做过这个:
$ ssh -N -R 19999:localhost:22 user@my.domain
Run Code Online (Sandbox Code Playgroud)
这有效,但如果出现问题,它会退出并且不会重新启动,并且不会在启动时启动,所以现在我添加一个 systemd 服务来运行:
/bin/bash -c "while true; do /usr/bin/ssh -i <unencrypted key> \
-o ServerAliveInterval=10 -v -o ServerAliveCountMax=6 -N \
-R 19999:localhost:22 user@my.domain; sleep 5; done"`
while true ... sleep 5 # re-runs ssh if it exits
Run Code Online (Sandbox Code Playgroud)
-o ServerAliveInterval=10
每 10 秒发送一次 keep-alive-o ServerAliveCountMax=6
如果 6 个 keep-alive 没有响应就退出-v
/var/log/messages
通过 systemd保留调试信息在服务器端,我添加了几行sshd_config
:
KeepAlive yes …
Run Code Online (Sandbox Code Playgroud)