13

解决ssh连接长时间不操作断开连接的问题(client_loop/ send disconnect/ Broken pipe...

 3 years ago
source link: https://www.pkslow.com/archives/ssh-keep-alive
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

解决ssh连接长时间不操作断开连接的问题(client_loop/ send disconnect/ Broken pipe)技术之前,先读诗书:

通过ssh连上服务器后,一段时间不操作,就会自动中断,并报出以下信息:

client_loop: send disconnect: Broken pipe

这带来很大的困扰,过一会就要重新连接,之前的临时环境变量也会丢失。

解决方案:

配置~/.ssh/config文件,增加以下内容即可:

Host *
        # 断开时重试连接的次数
        ServerAliveCountMax 5

        # 每隔5秒自动发送一个空的请求以保持连接
        ServerAliveInterval 5

添加在/etc/ssh/ssh_config应该也是可以的。


另一个类似问题:解决ssh的"Write failed: Broken pipe"问题

解决方法

方法一:如果您有多台服务器,不想在每台服务器上设置,只需在客户端的 ~/.ssh/ 文件夹中添加 config 文件,并添加下面的配置:

ServerAliveInterval 60

方法二:如果您有多个人管理服务器,不想在每个客户端进行设置,只需在服务器的 /etc/ssh/sshd_config 中添加如下的配置:

ClientAliveInterval 60

方法三:如果您只想让当前的 ssh 保持连接,可以使用以下的命令:

$ ssh -o ServerAliveInterval=60 user@sshserver

欢迎关注微信公众号<南瓜慢说>,将持续为你更新...

file

推荐阅读:
如何制定切实可行的计划并好好执行
容器技术(Docker-Kubernetes)
SpringBoot-Cloud相关
Https专题


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK