Parece que AutoSSH é a coisa certa para isso.
Autossh is a program to start a copy of SSH and monitor it, restarting it as necessary should it die or stop passing traffic. The original idea and the mechanism were inspired by RSTunnel (Reliable SSH Tunnel).
With version 1.2 the method changed: autossh began to use SSH to construct a loop of SSH forwardings (one from the local machine to the remote, and one from the remote to the local), and then send test data that it expects to get back. (The idea was thanks to Terrence Martin.)
With version 1.3, a new method was added (thanks to Ron Yorston): a port may be specified for a remote echo service that will echo back the test data. This avoids the congestion and the aggravation of making sure all the port numbers on the remote machine do not collide. The loop-of-forwardings method remains available for situations where using an echo service may not be possible.
Features
- autossh is a program to start a copy of ssh and monitor it, restarting it as necessary should it die or stop passing traffic. The idea is from rstunnel (Reliable SSH Tunnel), but implemented in C.
- The author's view is that it is not as fiddly as rstunnel to get to work.
- Connection monitoring using a loop of port forwardings or a remote echo service.
- Backs off on rate of connection attempts when experiencing rapid failures such as connection refused.
- Compiled and tested on OpenBSD, Linux, Solaris, Mac OS X, Cygwin, and AIX; should work on other BSDs.
- Freeware.