Leif160519的blog Leif160519的blog

——————

目录
解决Linux的SSH自动断线问题
/    

解决Linux的SSH自动断线问题

平时在命令行下ssh连接了远程服务器,经常才几分钟没操作就被自动断线了,不能进行任何操作,其实这是因为ssh没有设置心跳检测,可以通过以下两种方法解决。
1、依赖ssh客户端定时发送心跳检测,配置/etc/ssh_config文件,在末尾添加上,

ServerAliveInterval 20
ServerAliveCountMax 999

每隔20秒向服务器发出一次心跳检测,若超过999次请求都没有成功,就主动断开与服务器端的连接。
2、依赖ssh服务器端定时发送心跳检测,配置/etc/sshd_config文件(注意:这里是sshd_config,不是ssh_config),在末尾添加上,

ClientAliveInterval 30
ClientAliveCountMax 6

每隔30秒向客户端发出一次心跳检测,若超过6次请求都没有成功,就会主动断开与客户端的连接。
3、设置了ssh的心跳检测后,重启ssh服务才能生效,执行命令

service ssh restart

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill

标  题解决Linux的SSH自动断线问题
作  者Leif160519
出  处https://github.icu/articles/2019/08/22/1566472357161.html
关于博主:坐标南京,运维工程师,如有问题探讨可以直接下方留言。
声援博主:如果您觉得文章对您有帮助,可以评论、订阅、收藏。您的鼓励是博主的最大动力!