8ag5aq
Last Updated: December 14, 2017
·
18.37K
· slaykovsky
343aa9662f5530d974c46ddf6af8d799

SSH Broken Pipe fix (Mac OS X)

Hi!
There was a problem with my ssh connection with AzureVM. It was a suddenly disconnect with "Broken Pipe" error.
To fix it, on your mac do:

emacs (or vim/vi/nano/etc) ~/.ssh/config

And then, write this:

Host *
    ServerAliveInterval 120
    TCPKeepAlive no

Now it is fixed ^_^

Say Thanks
Respond

3 Responses
Add your response

17139
Ea9f3f355c67f0835b3dd3141e3cafc2

Thanks for the fix. Do you have understanding to provide a little background on why these settings fix the problem?

edit: after a little research:

ServerAliveInterval 120 means "If there is no activity for 120 seconds on the connection, send a request to the server, requesting a response." I believe this is useful because some servers are configured to drop inactive ssh sessions. This keeps the connection active so that doesn't happen.

TCPKeepAlive no means "do not send keepalive messages to the server". If the converse, TCPKeepAlive yes, were set, then the client sends keepalive messages to the server and requires a response in order to maintain its end of the connection. This will detect if the server goes down, reboots, etc. The trouble with this is that if the connection between the client and server is broken for a brief period of time, this will cause the keepalive messages to fail, and the client will end the connection with "broken pipe".  

Setting TCPKeepAlive no tells the client to just assume the connection is still good until proven otherwise by a user request, meaning that temporary connection breakages while your ssh term is sitting idle in the background won't kill the connection.

over 1 year ago ·
21798
None

The file in my mac OS X is located in /etc/ssh_config

over 1 year ago ·
26825

My file was at /etc/ssh/ssh_config

over 1 year ago ·
Filed Under