外网中转服务器上配置超时时间,例如间隔20s发送确认消息,最多发送3次,这样保证失联1min后将会切断连接
# /etc/ssh/sshd_config,记得重启sshd
ClientAliveInterval 20
ClientAliveCountMax 3
内网目标服务器上同样配置超时时间
# /etc/ssh/ssh_config
ServerAliveInterval 20
ServerAliveCountMax 3
目标服务器可以使用tmux运行
autossh -R 1024:localhost:1024 -o ExitOnForwardFailure=yes Server
参考资料:
https://www.jianshu.com/p/7ce35471a5ab
https://baijiahao.baidu.com/s?id=1716487922632955537&wfr=spider&for=pc