SSH 连接不断断开

SSH 连接不断断开

我已经配置了我的 SSH 连接,如下所示:~/.ssh/config在客户端

ServerAliveInterval 1
ServerAliveCountMax 1200

/etc/ssh/sshd_config服务器端:

ClientAliveInterval 5                                                                                                          
ClientAliveCountMax 1200             

尽管如此,当登录到远程服务器时,虽然我认为我的连接非常稳定,但我看到我的 SSH 连接在大约 15 到 60 秒后不断断开。ssh <server> -vvv总是以

...
debug3: send packet: type 80
debug3: receive packet: type 82
debug3: send packet: type 80
debug3: receive packet: type 82
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 1
debug3: send packet: type 100
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 80
debug3: send packet: type 1
Connection reset by <IP> port <PORT>

在服务器端:

...
debug3: receive packet: type 80                                                                                                
debug1: server_input_global_request: rtype [email protected] want_reply 1                                                  
debug3: send packet: type 82                                                                                                   
debug3: receive packet: type 80                                                                                                
debug1: server_input_global_request: rtype [email protected] want_reply 1                                                  
debug3: send packet: type 82                                                                                                   
debug2: channel 0: request [email protected] confirm 1                                                                     
debug3: send packet: type 98                                                                                                   
debug2: channel 0: request [email protected] confirm 1                                                                     
debug3: send packet: type 98                                                                                                   
debug2: channel 0: request [email protected] confirm 1                                                                     
debug3: send packet: type 98                                                                                                   
debug2: channel 0: request [email protected] confirm 1                                                                     
debug3: send packet: type 98
...                                                                                                 

服务器确实在不断重试。同时,我还可以下载某些内容,甚至可以打开与同一台服务器的并行 SSH 连接。

但即使发生短暂中断,为什么 SSH 客户端不会继续重试,而是过早退出?如何配置 SSH 以(真正)继续重试?

答案1

严格来说,这不是我的问题的解决方案,但至少我可以在另一个 shell 中运行一个进程来解决这个问题,该进程每秒并行登录到远程服务器,就像

 while true ; do ssh <server> "date; sleep 1s"; done

我不知道为什么,但它有效地防止了我上面最初的问题中提出的问题。

相关内容