If you are like me working on *nix systems remotly on your daily life, you might have seen this error “Write Failed:broken pipe” before when you ssh hop to a different server from your current *nix terminal session. It’s annoying when this happens — you lose your connection to the remote system and you have to initiate ssh session again. Fortunately there coule be an easy fix for it without touching the remote system sshd configuration.
You can add the following options in your ssh command:
TCPKeepAlive yes
ServerAliveInterval 30
ssh -o "TCPKeepAlive yes" -o "ServerAliveInterval 30" <remote_host>
TCPKeepAlive means as a client, sends TCP keepalive messages to the server. ServerAliveInterval means a timeout inverval in seconds if no data recieved from the server, the client will send a message through the encrypted channel to request a response from the server. Usually these two parameters should be enough. There is another parameter you could try — ServerAliveCountMax. With the default value 3 for this parameter, if the client doesn’t receive any response with the interval defined, it will retry 3 times. For a complete explaination of these options, see man page 5 of ssh_config.
On a redhat linux system, you could add options under “Host *” in /etc/ssh/ssh_config. Then you don’t have to specify them as options in the command line.
On the server side, there are corresponding parameters which could be set in /etc/ssh/sshd_config.
ClientAliveInterval 30
ClientAliveCountMax 5
TCPKeepAlive yes