Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Sometimes my SSH session disconnects with a Write failed: Broken pipe message. What does it mean? And how can I keep my session open?

I know about screen, but that's not the answer I'm looking for. I think this is a sshd config option.

share|improve this question
add comment

4 Answers 4

up vote 32 down vote accepted

It's possible that your server closes connections that are idle for too long. You can update either your client (ServerAliveInterval) or your server (ClientAliveInterval)

 ServerAliveInterval
         Sets a timeout interval in seconds after which if no data has
         been received from the server, ssh(1) will send a message through
         the encrypted channel to request a response from the server.  The
         default is 0, indicating that these messages will not be sent to
         the server.  This option applies to protocol version 2 only.

 ClientAliveInterval
         Sets a timeout interval in seconds after which if no data has
         been received from the client, sshd(8) will send a message
         through the encrypted channel to request a response from the
         client.  The default is 0, indicating that these messages will
         not be sent to the client.  This option applies to protocol
         version 2 only.

To update your server (and restart your sshd)

echo "ClientAliveInterval 60" | sudo tee -a /etc/ssh/sshd_config

Or client-side:

echo "ServerAliveInterval 60" >> ~/.ssh/config 
share|improve this answer
add comment

To make a complementary of Gert's answer, I wrote this article to solve this SSH issue: http://nextspaceship.com/2011/09/how-to-solve-broken-pipe-message-in-ssh-session/ Sometimes the network is unstable, so we need a script to auto restart the ssh session, don't we?

share|improve this answer
1  
Instead of creating a custom solution, does harding.motd.ca/autossh fulfill your needs? –  bbaja42 May 22 '12 at 7:22
3  
Hello from 2014. The link in this answer no longer works. –  CptSupermrkt May 27 at 15:07
    
The page is now at liangsun.org/posts/… –  sep332 Jun 26 at 21:12
add comment

It usually means that your network (TCP) connection was reset. E.g. your internet provider reconnected you or something like this.

share|improve this answer
add comment

Another cause for the "Broken Pipe message" is that another machine is attempting use the same IP as your host.

A simple way to test if someone else is using that IP:

  1. Turn off your host
  2. ping the same IP to see if another machine is using that IP

To find out which machines are on your network, you can use this Unix & Linux question title: How to find what other machines are connected to the local network.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.