autossh
TLDR
Create persistent SSH tunnel
$ autossh -M [20000] -N -L [8080:localhost:80] [user@remote]
Tunnel with no monitoring port$ autossh -M 0 -N -L [8080:localhost:80] [user@remote]
Reverse tunnel$ autossh -M [20000] -N -R [8080:localhost:80] [user@remote]
Run in background$ autossh -f -M [20000] -N -L [8080:localhost:80] [user@remote]
SYNOPSIS
autossh -M monitorport [sshoptions] destination
DESCRIPTION
autossh wraps SSH connections with automatic reconnection. It monitors the connection and restarts it if it dies, making SSH tunnels and connections persistent.
The tool is essential for maintaining long-running SSH tunnels, remote port forwards, and SOCKS proxies.
PARAMETERS
-M port[:port]
Monitoring port(s). Use -M 0 to disable port monitoring-f
Background after authentication-N
No command execution (forwarding only)-L port:host:port
Local port forward-R port:host:port
Remote port forward-D port
SOCKS proxyAll other ssh options are supported.
ENVIRONMENT VARIABLES
AUTOSSH_GATETIME
Seconds before first connection check (default: 30)AUTOSSH_POLL
Poll time in seconds (when monitoring disabled)AUTOSSH_DEBUG
Enable debug logging
CAVEATS
Monitoring ports must be free on both sides. ServerAliveInterval in SSH config can replace monitoring. May not detect all disconnection types. Recent SSH versions have built-in keepalives.
HISTORY
autossh was created by Carson Harding to address the problem of SSH connections dying without notification, first released around 2002.


