8

What's the best way to automatically reconnect an interactive SSH session to re-establish the shells on terminals? I looked at autossh but that seems to be dedicated to port forwards (which I do not need).

Is there any shell-fu or utility that allows that?

Gaff
  • 18,569
  • 15
  • 57
  • 68
wishi
  • 335
  • 1
  • 7
  • 19

2 Answers2

9

Actually, autossh will do the same for interactive sessions as well - you may want to run the remote session in screen to keep it up across reconnects:

autossh -t you@somehost.example.com 'screen -R'

As autossh accepts the parameters that ssh does, the -t option will force a terminal (which is needed for an interactive session), and screen -R will preserve your shell across reconnects.

  • the -t option is not in 1.4c-1, is it? – wishi Oct 26 '11 at 14:14
  • /usr/share/autossh/examples/rscreen does that. with -t this is broken and connot work. – wishi Oct 26 '11 at 14:33
  • @wishi: I have `autossh 1.4b` here, and `OpenSSH_5.3p1debian-3ubuntu7, OpenSSL 0.9.8k 25 Mar 2009`. I have never yet encountered the behavior you specified - the `-t` switch has been in ssh for ages and ages (see ssh manpage); autossh passes the parameters it doesn't recognize to ssh (perhaps this is a regression in autossh?) Also, I don't have the .../examples/rscreen file on my system. Note that I have actually tried the command, on multiple Linux systems with different distros, and it works (therefore I vehemently oppose your assertion that it "cAnnot work"). – Piskvor left the building Oct 26 '11 at 17:32
3

Perhaps: while true; do ssh user@host; done ??

Helps to run screen on the remote host to be able to pick up exactly where you left off.

glenn jackman
  • 25,463
  • 6
  • 46
  • 69
  • Note that in some circumstances, a SSH session might simply hang instead of terminating. Autossh tries to mitigate this by pinging itself through the connection, and restarting if it looks unresponsive. However for environments where only ssh is available (or some stripped down ssh client even - embedded devices etc.), your solution would be the easiest solution. – Piskvor left the building Oct 02 '15 at 14:42