Keeping your SSH connections alive with autossh

With autossh, you can monitor your SSH connections and restart them if they stop sending traffic or SSH exits abnormally. This makes autossh perfect for keeping secure port forwarding available.

Some readers will be familiar with the TCPKeepAlive, ServerAliveInterval, and ServerAliveCountMax options to SSH itself. TCPKeepAlive causes TCP keepalive messages to be sent to the server, allowing SSH to detect if it can no longer contact the server. ServerAliveCountMax and ServerAliveInterval cause the SSH client to send traffic through the encrypted link to the server, and can be used both the avoid a connection being closed due to inactivity and to have the SSH client exit if traffic cannot be returned from the server for a specified amount of time. The default action if TCPKeepAlive messages are ignored or ServerAliveCountMax messages are not returned in time is for the SSH client to exit.