Autossh

Install...

emerge -av net-misc/autossh

(there are no USE flags for this package)

Basic Instructions

These are available at the autossh website and its README file:
 * http://www.harding.motd.ca/autossh/
 * http://www.harding.motd.ca/autossh/README

Important Tips

The "-M" option is required, even if you don't want to use the monitoring option (in which case, use "-M 0").

When using "-M"...
 * Connections are tunnelled. No firewall changes needed for autossh's monitoring feature.
 * Ports need to be above 1024 if you are not logging in as root.
 * If you use a password prompt, then autossh will wait for your password when it reconnects, and it won't be fully connected until you give that password.

Example

This example uses SSH port 222 on the remote server, and sets up a SOCKS proxy on port 9999. The "sleep" command is used instead of SSH's "-N" option so that a "Connected" message is provided upon successful login.

autossh -M 0 -p 222 -D 9999 -o "ServerAliveInterval 45" -o "ServerAliveCountMax 2" root@myserver 'echo && echo -e "Connected.\n" && sleep 9999999'