Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There's a server I'd like to be connected to at all times that I have an internet connection. Sometimes I turn off my laptop, sometimes my connection drops, sometimes I go from wired to wireless or vice versa. Is there any solution to get it to automatically reconnect whenever possible and resume my screen session?

share|improve this question
Are you running windows or linux on your laptop? – pgs Jun 29 '09 at 4:22
Linux Please enter at least 15 characters – user10986 Jun 29 '09 at 4:45

I suspect that autossh, possibly with a little bit of scripting to automatically reconnect to the screen session, will be the way to go.

share|improve this answer
Telling ssh to execute 'screen -DR' at the remote host is likely to be sufficient. – pgs Jun 29 '09 at 4:30
You'll probably want to throw a -t at SSH, in that case, but yeah I think that'll work. – womble Jun 29 '09 at 4:49
screen, definitely. – Steve Lacey Jun 29 '09 at 6:30
@Steve Lacey: Huh? – womble Jun 29 '09 at 9:04

I've never used it myself, but if I remember my hearsay correctly, Putty Tray will do that

Please comment if I'm wrong and leading John down the wrong path.

share|improve this answer
Looks like a good solution for windows clients. – pgs Jun 29 '09 at 5:13
D'oh! I missed John's comment above about it being a linux box. Thanks for subtly remarking that, pgs ;) – msanford Jun 29 '09 at 6:09

You could consider running ssh in a wrapper script.

while ! ssh "$@"; do
   echo "Reconnecting..." >/dev/stderr

Call the script "ssh-forever" and use it with, for example:

$ ssh-forever -t user@host screen -DR
share|improve this answer
Actually, it looks like autossh already does this. It might be better to use that instead of rolling your own script. – RJHunter Jun 29 '09 at 5:04

screen command is what you need, you can attach or detach to the terminal from different locations:

share|improve this answer
I suspect that the OP already knows about screen, given that he said "resume my screen session"... – womble Jun 29 '09 at 4:07
His original question already says "and resume my screen session". What he wants is a client that will do automatic reconnects when the connection is lost. – pgs Jun 29 '09 at 4:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.