SSH automatic reconnect on timeout
There may already be some builtin option that allows a client to reconnect when a timeout occurs but I was too lazy to look through the man pages. So I came up with line of bash commands that will do just that:
This will keep reconnecting to the host 120 seconds after a connection drops out for whatever reason. This is specially handy to make sure that a remote tunnel stays open. Right now I use it to reach a single host (A,http) on a remote private network from home (B) via another machine in the private network (C) and an intermediate SSH server (D):
Now it is possible to type "http://A" and visit the site from B as easily as from within the remote private network.
$ while [ 1 ]; do ssh user@host.domain; sleep 120; done
This will keep reconnecting to the host 120 seconds after a connection drops out for whatever reason. This is specially handy to make sure that a remote tunnel stays open. Right now I use it to reach a single host (A,http) on a remote private network from home (B) via another machine in the private network (C) and an intermediate SSH server (D):
[user@C ~]$ while [ 1 ]; do ssh -R someport:A:80 user@D; sleep 120; done
[user@B ~]$ ssh -L 80:localhost:someport user@D
[root@B ~]# echo "127.0.0.1 A" >> /etc/hosts
Now it is possible to type "http://A" and visit the site from B as easily as from within the remote private network.
2 Comments:
hi, i've found your howto via google, but find another post which told me to install autossh ;-)
this is a very "simple" but most useful prog.: http://www.harding.motd.ca/autossh/
bests, thx, PasiC
Thanks for the pointer PasiC!
Post a Comment
<< Home