6

解决阿里云、腾讯云等云主机 SSH 短时间内无操作则自动断开连接的问题

 2 years ago
source link: http://i.lckiss.com/?p=7449
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.

解决阿里云、腾讯云等云主机 SSH 短时间内无操作则自动断开连接的问题

2021-08-21

一般来说,长时间不操作主机,确实断开比较安全,但阿里云和腾讯云不知道什么时候开始变得其短无比,以至于我改改命令再粘贴上去的时候就已经不再响应,是在是影响体验。简单贴几条命令:

vi /etc/ssh/sshd_config

将以下字段进行适当修改:

ClientAliveInterval 120
ClientAliveCountMax 3

通过字面意思可知:

ClientAliveInterval 为心跳包间隔,120 则意思服务器每 2 分钟进行一次心跳包发送,客户端有响应则继续保持连接。

ClientAliveCountMax 则是当客户端无响应达到一定次数时则断开连接。

改完保存,重启服务即可:

systemctl restart sshd.service

参考:https://man.openbsd.org/sshd_config


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK