I'm having problem that my network router reboots occasionally and because of that my ssh connection via terminal to my Ubuntu server is ended. The internet connection is just temporary disrupted and don't want to processes I'm running in the terminal are killed.

On my client ~/.ssh/config I have:

TCPKeepAlive yes
ServerAliveCountMax 10
ServerAliveInterval 5

But tuning of the above parameters does not help. The server sshd has default ubuntu parameters.

How to setup ssh on client (Mac OS in my case) and sshd on server (Ubuntu in my case) so that my ssh sessions survive reboot of router?



Due to the nature of the underlying protocol ssh uses (TCP), the connections will drop after a certain amount of timeout. I tend to get around these issues in one of two ways:

1) use screen on the remote server and re-attach after the connection is restored. 2) setup up a VPN (such as openvpn) and use udp transmission, which allows for network interruptions (as well as, with a bit of configuration, source IP changes).


Since your server and client are both well supported, I highly recommend MOSH. MOSH uses SSH, but is designed for mobility, so that you can connect, disconnect, change IP, etc., and it will try to do the right thing and keep you connected. Even if you get disconnected, it will auto-connect, and put you right back where you were.

The main down-side to MOSH is that it does require installing extra software and it is not supported on every platform. Windows has semi-native support via MobaXTerm, and it doesn't work on things like VMWare ESXi, which have only vanilla SSH support.

MOSH also helps on slow links by enabling "predictive input", where what you type basically echos locally while the system figures out whether or not it really should.


You can accomplish this with autossh

a simple program that allows you to run an instance of ssh - keeps it under control, and restarting the same instance once that the connection is dropped up to a maximum number of times controlled by the environment variable AUTOSSH_MAXSTART or indefinitely if the value of this is negative (the default).

Combining this solution with screen (first mentioned by Drav) is even better.


Your above mentioned parameter must be set on the ssh server site as well. Only on client side did not help. If you do not have the rights to fit the sshd configuration. I might use ssh clients which support an inherent ssh keep live. The send some data to keep the connection up. Putty can do that for windows, SecureCRT can do that mac. Perhaps there are additional clients out there, which support this feature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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