Running autossh
autossh -M 0 <host>
Supervised login session
A normal exit (typing exit) ends autossh too; only failures
restart ssh.
autossh -M 0 -N -L <lport>:<dst>:<dport>
<host>
Keep a local forward alive
autossh -M 0 -N -R <rp>:localhost:<p>
<host>
Keep a reverse tunnel alive
autossh -M 0 -N -D <port> <host>
Keep a SOCKS proxy alive
autossh -M 0 -f -N <ssh args>
Drop to the background
-f is autossh's own: ssh cannot then ask for passwords or
passphrases.
autossh -M 0 -N -J <jump> <host>
Supervise a tunnel via a jump host
autossh -M 0 -i <key> -p <port>
<user>@<host>
Choose key and port as for ssh
autossh -M 0 -F <config> <host>
Use another ssh config file
autossh -V
Show the autossh version
Monitoring
-M 0
Disable the monitor port, rely on ssh keepalives
Needs ServerAliveInterval/ServerAliveCountMax so ssh exits
when the link dies.
-M <port>
Monitor with a port pair
Uses <port> and <port>+1 locally and on the
remote; both must be free.
-M <port>:<echo_port>
Monitor via a remote echo service
Port 7 is the inetd echo service, often disabled.
-o ServerAliveInterval=30 -o ServerAliveCountMax=3
Ssh quits after ~90 s of silence
-o ExitOnForwardFailure=yes
Exit ssh if a forward cannot bind
-o ConnectTimeout=10
Fail fast when the host is down
-o BatchMode=yes
Never prompt: fail instead
-o StrictHostKeyChecking=accept-new
Trust new hosts on first connect
-o TCPKeepAlive=yes
Enable TCP-level keepalives
Environment variables
AUTOSSH_GATETIME=<s>
Seconds ssh must survive to count as started (30)
0 disables the gate and retries even if the first ssh fails
with status 1. Useful at boot.
AUTOSSH_POLL=<s>
Seconds between connection tests (600)
AUTOSSH_FIRST_POLL=<s>
Delay before the first test
AUTOSSH_PORT=<port>
Monitor port; overrides -M
AUTOSSH_DEBUG=1
Debug log, copied to stderr
AUTOSSH_LOGLEVEL=<0-7>
Syslog level, 7 chattiest
AUTOSSH_LOGFILE=<file>
Log to a file instead of syslog
AUTOSSH_PIDFILE=<file>
Write the autossh pid
AUTOSSH_PATH=<path>
Use this ssh executable
AUTOSSH_MAXSTART=<n>
Start ssh at most n times (-1: no limit)
AUTOSSH_MAXLIFETIME=<s>
Stop everything after this many seconds
AUTOSSH_MESSAGE=<text>
Append text to the test message