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

參考文章:

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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM