Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

What can I do to configure SSH on both client and servers to prevent Write Failed: broken pipe errors, which ofter occurs if you sleep your client computer and resume later.

share|improve this question
1  
Nothing really. The session was interrupted, and the security of the session was compromised. If you don't put the comp to sleep you can set a keep alive time for the client to shoot a keep alive heart beat to the server, but if the system's going to sleep then there is nothing that can be done. – darkdragn Apr 28 '12 at 23:44
SHH sessions rotate encryption keys over time, to prevent long timescale brute force attacks. Sleep / resume will break this security and the connection. – david6 Apr 29 '12 at 1:58
In this case I'm looking for something that would allow me to re-initiate a broken ssh connection (based probably on the exit code) and restore using screen? – Sorin Sbarnea Apr 30 '12 at 7:11

3 Answers

I have tried this in /etc/ssh/ssh_config for Linux and ~/.ssh/config for Mac:

ClientAliveInterval 120
ServerAliveInterval 120

This is how often, in seconds, it should send a keepalive message to the server. If that doesn't work then train a monkey to press enter every two minutes while you work.

share|improve this answer
Yeah I do similar and it works quite well for most things. – Oli Aug 25 '12 at 0:25
I'm not on a Mac, but Ubuntu 12.04 and the file for this operating system also seems to be ~/.ssh/config. – broiyan Dec 14 '12 at 13:26

I'm remotely upgrading an Ubuntu server from lucid to precise and lost the ssh connection in the middle of the upgrade with the message "Write failed. Brocken pipe". ClientAliveInterval and ServerAliveInterval did nothing. The solution is to turn on TCPKeepAlive options in client ssh:

TCPKeepAlive yes

in

/etc/ssh/ssh_config
share|improve this answer

SSH sessions may break due to numerous and possibly unavoidable reasons.

A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run screen in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running screen -d then screen -r will reopen the last session and you will be able to continue from there. Make sure you read some of the documentation before using it.

share|improve this answer

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.