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 機能。