There are hundreds of questions and answers on various websites on Broken Pipe issue. The problem is essentially closed connection when a SSH session is not kept active by typing or running command. None of those websites can explain or give a universal easy fix. Readers report us of packet_write_wait: Connection to port 22: Broken pipe. Here is how to fix write failed broken pipe on mac, gnu/linux. It is actually easy matter.
Fix Write Failed Broken Pipe (packet_write_wait: Connection to port 22: Broken pipe)
The error is common after new installation of a unix or unix like operating systems or upgrade of such operating systems. Easiest way to keep the session active for a predefined period is to SSH on the server with command of this format :
1 | ssh -o ServerAliveInterval=60 username@IP_ADDRESS |
ServerAliveInterval=
is variable in minutes. 60 is one hour. username
is something which you use to SSH like root
by default. IP_ADDRESS
is the IP address of your server.
---
Why Various Q&A Site Fails To Fix Write Failed Broken Pipe & Why It Happens?
It happens out of wrong permission, ownership of the files, directories related to SSH after an upgrade. It is essentially a security feature of unix or unix like operating systems. Run a ls -al
on your Mac of Linux desktop/laptop (client) :
1 | ls -al /etc/ssh/sshd_config |
You will notice that result will be like this :
1 | -rw-r--r-- 1 root wheel 3351 Jun 24 02:14 /etc/ssh/sshd_config |
Owner belongs to unix wheel group. For MacOS X, for each version there are different ways to get root access on your Mac which is available on Apple’s website. Even if you enabled for older version of MacOS X, you need to follow this guide for the newer MacOS X like Sierra in our example :
1 | https://support.apple.com/en-us/HT204012 |
You can also of it from command line by running :
1 | dsenableroot |
Apple has some security fixes, which makes becoming root difficult. You can read this documentation of sudo :
1 | https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man8/sudo.8.html |
Open Terminal, not iTerm2 and Oh My ZSH and run :
1 | sudo -s |
As root you can modify ownership, permission of the files owned by root, wheel group. As root user, run this command to find the configuration file :
1 | find / -name sshd_config |
Which sshd_config
is used is complicated matter for ZSH/Oh-My-ZSH like shells – it can be /etc/ssh_config
, /etc/ssh/ssh_config
, even inside the private directory. Basically on the sshd_config
you need to add/modify :
1 2 3 | ClientAliveCountMax 4 ClientAliveInterval 30 TCPKeepAlive yes |
At worse, there are more files to config. The .bashrc
or .zshrc
should have :
1 2 3 | TMOUT=300 readonly TMOUT export TMOUT |
There is ~/.ssh/config
, which should have :
1 2 3 | Host * ServerAliveInterval 300 TCPKeepAlive no |
Shut down the Mac and switch on. If still problem persists, you need to change the ownership of the files to the user’s name. Running :
1 | ssh -o ServerAliveInterval=60 username@IP_ADDRESS |
is safe and secured way for your servers and Mac.
Tagged With packet_write_wait: Connection to port 22: Broken pipe , packet_write_wait broken pipe , port 22: broken pipe , packet_write_wait: Connection to UNKNOWN port 65535: Broken pipe , write failed: broken pipe , packet_write_wait: connection to broken pipe , packet_write_wait , packet write wait broken pipe , port 22 broken pipe , connection to 10 170 4 14 port 22: broken linux