I often have to connect to a server over ssh in an unreliable wifi environment. On the server, I run screen, so if I get disconnected, I can reconnect and resume the screen session, and pick up where I left off, but the loss of connection is still a major time sink: if the connection drops out while I'm on the server, the terminal window tends to freeze. I have to kill that tab, open a new one, ssh to the server again and resume the screen session. I've tried this with running screen on the server and screen locally. Either way it tends to freeze when the connection drops out.
Is there any way I can have something similar to screen, or maybe screen itself, that will automatically try to reconnect and keep the session running, so I don't have to keep manually reconnecting? Often when I lose the connection I think it's only for a very brief period – less than a second maybe.
I'm using Ubuntu 14.04 LTS, MATE edition. thanks
Best Answer
You could look at using
mosh
: https://mosh.org/You could set up a 'jump' server with a reliable internet connection which you use
mosh
to connect to, then havessh
sessions to each server you manage. The reason I suggest using a jump server is that you may not wish to installmosh
on the servers you are managing.Another advantage of
mosh
is that it is based on UDP rather than TCP, and your session can survive a change of IP address, for example going from WiFi to a mobile internet connection.Just to make it clear,
mosh
is not a replacement forscreen
, but ratherssh
. It's still a good idea to usescreen
with it, sincemosh
itself doesn't provide a way to reconnect to your session if the client dies for some reason.