1. 程式人生 > >ssh登陸報錯:packet_write_wait: Connection to x.x.x.x port 22: Broken pipe

ssh登陸報錯:packet_write_wait: Connection to x.x.x.x port 22: Broken pipe

多臺 tro following eat ESS and config 說明 user

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. users configuration file (~/.ssh/config) 3. system-wide configuration file (/etc/ssh/ssh_config)

ssh登陸報錯:packet_write_wait: Connection to x.x.x.x port 22: Broken pipe