SSH - 防止自动接续切断

SSH 接续时,放置一定时间后,会自动切断SSH的接续

防止

方法一

设置路由器 - 不推荐

方法二

设定客户端和服务器的定期应答确认 服务器端或者客户端的任意一方设置即可

服务器端

不建议修改服务器端,
EC2上修改服务器端,出现错误后,直接连不上SSH,需要修复磁盘才可以,
非常麻烦,修复方法参照 EC2 - SSH连接时・ Connection refused的解决方法

/etc/ssh/sshd_config
ClientAliveInterval [秒数]
ClientAliveCountMax [回数]

客户端

/etc/ssh/ssh_config  或者  ~/.ssh/config
ServerAliveInterval [秒数]
ServerAliveCountMax [回数]

重新启动

CentOS7場合

//sudo /etc/rc.d/init.d/sshd restart
sudo systemctl start sshd.service

Ubuntu場合

sudo /etc/init.d/ssh restart

MacOS場合

sudo launchctl stop com.openssh.sshd
或者
系统环境设定 > 共享 > 远程登陆  先OFF → 再ON

Amazon EC2場合

$ sudo /usr/sbin/sshd -t
→没有错误信息OK
或者
$ sudo /etc/rc.d/init.d/sshd restart
sshd 停止中:            [ OK ]
sshd 起動中:            [ OK ]

方法三

客户端定期向服务器端发送无效包
例如 Putty 等提供的 Heartbeat/KeepAlive 机能。

猜你喜欢

转载自blog.csdn.net/oblily/article/details/88055196
ssh