SSH连接总是定期断掉的解决办法

分享于:2019-01-24 14:56:15

SSH连接总是隔一段时间没有输入时就断开,解决办法如下:


服务端配置

sudo vi /etc/ssh/sshd_config
ClientAliveInterval 60     #服务端主动向客户端请求响应的间隔
ClientAliveCountMax 10    #服务器发出请求后客户端没有响应的次数达到一定值就自动断开
sudo restart ssh

客户端配置 

sudo vi /etc/ssh/ssh_config  #或~/.ssh/config
TCPKeepAlive=yes
ServerAliveInterval 60   #客户端主动向服务端请求响应的间隔

ssh -i <key-file> -o StrictHostKeyChecking=no -o TCPKeepAlive=yes -o ServerAliveInterval=30 ubuntu@<ip>

上面方式任选一种,我选客户端配置方式。


原文:https://blog.csdn.net/quqi99/article/details/51434248