參考文章:服務器
https://patrickmn.com/aside/how-to-keep-alive-ssh-sessions/session
用 ssh 命令鏈接服務器以後,若是一段時間不操做,再次進入 Terminal 時會有一段時間沒有響應,而後就出現錯誤提示:ssh
packet_write_wait: Connection to 47.92.226.106 port 22: Broken pipe
只能從新用 ssh 命令進行鏈接。ide
Solution:ui
1.若是有多臺服務器,不想在每臺上設置,只需在客戶端設置便可:spa
/etc/ssh/ssh_config
~/.ssh/config
(create the file if it doesn’t exist) Host *
ServerAliveInterval 300
ServerAliveCountMax 2
2. 若是有多臺我的管理服務器,能夠在服務器端配置:(沒有效果!!)code
make your OpenSSH server keep alive all connections with clients by adding the following to /etc/ssh/sshd_config
:server
ClientAliveInterval 300 ClientAliveCountMax 2
這些設置讓ssh client or server發送一個空包到另外一端,每5分鐘一次。blog
若是它在嘗試了2次後,仍沒有收到任何響應,則放棄。即鏈接被斷開了。ip
經過man ssu_config能夠看到詳細說明:
SYNOPSIS ~/.ssh/config /etc/ssh/ssh_config DESCRIPTION ssh(1) obtains configuration data from the following sources in the following order: 1. command-line options 2. user's configuration file (~/.ssh/config) 3. system-wide configuration file (/etc/ssh/ssh_config)