SSH 连接不断掉线

Rob*_*ert 5 networking linux ssh

我已按如下方式配置 SSH 连接:~/.ssh/config在客户端

ServerAliveInterval 1
ServerAliveCountMax 1200
Run Code Online (Sandbox Code Playgroud)

并在/etc/ssh/sshd_config服务器端:

ClientAliveInterval 5                                                                                                          
ClientAliveCountMax 1200             
Run Code Online (Sandbox Code Playgroud)

尽管如此,当登录到远程服务器时,虽然我认为我的连接相当稳定,但我发现我的 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 keepalive@openssh.com 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>
Run Code Online (Sandbox Code Playgroud)

在服务器端:

...
debug3: receive packet: type 80                                                                                                
debug1: server_input_global_request: rtype keepalive@openssh.com want_reply 1                                                  
debug3: send packet: type 82                                                                                                   
debug3: receive packet: type 80                                                                                                
debug1: server_input_global_request: rtype keepalive@openssh.com want_reply 1                                                  
debug3: send packet: type 82                                                                                                   
debug2: channel 0: request keepalive@openssh.com confirm 1                                                                     
debug3: send packet: type 98                                                                                                   
debug2: channel 0: request keepalive@openssh.com confirm 1                                                                     
debug3: send packet: type 98                                                                                                   
debug2: channel 0: request keepalive@openssh.com confirm 1                                                                     
debug3: send packet: type 98                                                                                                   
debug2: channel 0: request keepalive@openssh.com confirm 1                                                                     
debug3: send packet: type 98
...                                                                                                 
Run Code Online (Sandbox Code Playgroud)

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

但即使是短暂的中断,为什么 SSH 客户端不继续重试而是提前退出呢?如何配置 SSH(真正)继续重试?

Rob*_*ert 1

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

 while true ; do ssh <server> "date; sleep 1s"; done
Run Code Online (Sandbox Code Playgroud)

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