执行3条命令即可
第1条:写入内核保活参数(复制整段直接敲)
shell
cat >> /etc/sysctl.conf <<EOF
net.ipv4.tcp_keepalive_time = 60
net.ipv4.tcp_keepalive_intvl = 10
net.ipv4.tcp_keepalive_probes = 3
EOF
shell
vim /etc/ssh/sshd\_config
TCPKeepAlive yes
ClientAliveInterval 60
ClientAliveCountMax 30
第2条:让 sysctl 配置立刻生效
shell
sysctl -p
第3条:重启 ssh 服务,加载 sshd_config 里面的保活配置
shell
systemctl restart ssh
补充:如果系统是CentOS/AlibabaCloudLinux 则使用如下命令:
shell
systemctl restart sshd