ssh登陆报错:packet_write_wait: Connection to x.x.x.x port 22: Broken pipe
参考文章:
https://patrickmn.com/aside/how-to-keep-alive-ssh-sessions/
用 ssh 命令连接服务器之后,如果一段时间不操作,再次进入 Terminal 时会有一段时间没有响应,然后就出现错误提示:
packet_write_wait: Connection to 47.92.226.106 port 22: Broken pipe
只能重新用 ssh 命令进行连接。
Solution:
1.如果有多台服务器,不想在每台上设置,只需在客户端设置即可:
- 全部都保持连接:(root access required), edit
/etc/ssh/ssh_config
- 只在你的user上设置:edit
~/.ssh/config
(create the file if it doesn’t exist)
Host *
ServerAliveInterval 300
ServerAliveCountMax 2
2. 如果有多台个人管理服务器,可以在服务器端配置:(没有效果!!)
make your OpenSSH server keep alive all connections with clients by adding the following to /etc/ssh/sshd_config
:
ClientAliveInterval 300 ClientAliveCountMax 2
这些设置让ssh client or server发送一个空包到另一端,每5分钟一次。
如果它在尝试了2次后,仍没有收到任何响应,则放弃。即连接被断开了。
通过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)