Ssh – causing the famous “broken pipe” when I use tmux inside an SSH session

linux-networkingsshtmux

Scenario1:
I SSH from my employer (OSX Yosemite SSH client) to my home server (Debian stable) and (re)connect to a tmux session. If I leave the terminal inactive for a while (~20minutes), it seems like the network connection has been interrupted for too long with the famous SSH error: "broken pipe". If I log back in the tmux behaves as expected: the session is still alive.

Scenario2: I SSH from my employer to my home box. Now I do the stuff I usually do but this time not in a tmux session. Now I can leave the terminal inactive for hours and hours, it does not die.

Scenario 3: I SSH from my own home network segment to the same server and connect to a tmux session. Now I get the expected behaviour. The terminal does not lose the connection after a period of inactivity, with our without using tmux.

I have tried to Google my question but the problem is that I get answers to the wrong question:
Q: I use SSH for a long running command, how can I reconnect if I get a broken pipe?
A: Have you heard of tmux?
Yes I have … . But I haven't heard of broken pipes being caused by tmux.

I also asked the question on irc but I didn't get a reply there.

Best Answer

Enable SSH keepalives globally in /etc/ssh_config or in your home directory ~/.ssh/config

KeepAlive yes
ServerAliveInterval 60

Before I found this openssh option, I would run "top -d 60" to keep the connection alive.

Related Topic