2016-01-08 04:41:27 +00:00
|
|
|
# autossh
|
|
|
|
|
2021-04-17 02:42:33 +01:00
|
|
|
> Run, monitor and restart SSH connections.
|
|
|
|
> Auto-reconnects to keep port forwarding tunnels up. Accepts all `ssh` flags.
|
|
|
|
> More information: <https://www.harding.motd.ca/autossh>.
|
2016-01-08 04:41:27 +00:00
|
|
|
|
2024-02-09 14:34:08 +00:00
|
|
|
- Start an SSH session, restarting when the [M]onitoring port fails to return data:
|
2016-01-08 04:41:27 +00:00
|
|
|
|
2021-04-17 02:42:33 +01:00
|
|
|
`autossh -M {{monitor_port}} "{{ssh_command}}"`
|
2016-01-08 04:41:27 +00:00
|
|
|
|
2024-02-09 14:34:08 +00:00
|
|
|
- Forward a [L]ocal port to a remote one, restarting when necessary:
|
2016-01-08 04:41:27 +00:00
|
|
|
|
|
|
|
`autossh -M {{monitor_port}} -L {{local_port}}:localhost:{{remote_port}} {{user}}@{{host}}`
|
|
|
|
|
2024-02-09 14:34:08 +00:00
|
|
|
- Fork `autossh` into the background before executing `ssh` and do [N]ot open a remote shell:
|
2016-01-08 04:41:27 +00:00
|
|
|
|
2021-04-17 02:42:33 +01:00
|
|
|
`autossh -f -M {{monitor_port}} -N "{{ssh_command}}"`
|
2016-01-08 04:41:27 +00:00
|
|
|
|
2021-04-17 02:42:33 +01:00
|
|
|
- Run in the background, with no monitoring port, and instead send SSH keep-alive packets every 10 seconds to detect failure:
|
2016-01-08 04:41:27 +00:00
|
|
|
|
2021-04-17 02:42:33 +01:00
|
|
|
`autossh -f -M 0 -N -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" "{{ssh_command}}"`
|
2016-01-08 04:41:27 +00:00
|
|
|
|
2021-04-17 02:42:33 +01:00
|
|
|
- Run in the background, with no monitoring port and no remote shell, exiting if the port forward fails:
|
2016-01-08 04:41:27 +00:00
|
|
|
|
|
|
|
`autossh -f -M 0 -N -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -o ExitOnForwardFailure=yes -L {{local_port}}:localhost:{{remote_port}} {{user}}@{{host}}`
|
|
|
|
|
2021-04-17 02:42:33 +01:00
|
|
|
- Run in the background, logging `autossh` debug output and `ssh` verbose output to files:
|
2016-01-08 04:41:27 +00:00
|
|
|
|
2021-04-17 02:42:33 +01:00
|
|
|
`AUTOSSH_DEBUG=1 AUTOSSH_LOGFILE={{path/to/autossh_log_file.log}} autossh -f -M {{monitor_port}} -v -E {{path/to/ssh_log_file.log}} {{ssh_command}}`
|