How to setup ssh on Mac OS (client) and on server (ubuntu) to recover from temporary connection lost

1

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?

Thanks!

Robert Grezan

Posted 2013-07-26T21:33:42.153

Reputation: 175

possible duplicate of SSH tunnel in Ubuntu

– dtmland – 2013-07-26T22:42:06.253

Related: How can I logout an open, remote SSH session? – Breakthrough – 2013-07-31T17:42:53.687

Answers

2

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).

Drav Sloan

Posted 2013-07-26T21:33:42.153

Reputation: 396

1

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.

Noah Silva

Posted 2013-07-26T21:33:42.153

Reputation: 11

0

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.

dtmland

Posted 2013-07-26T21:33:42.153

Reputation: 2 281

0

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.

ryder

Posted 2013-07-26T21:33:42.153

Reputation: 147