tldr/pages/common/autossh.md

30 lines
1.3 KiB
Markdown
Raw Permalink Normal View History

# 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>.
2021-04-17 02:42:33 +01:00
- Start an SSH session, restarting when a monitoring port fails to return data:
2021-04-17 02:42:33 +01:00
`autossh -M {{monitor_port}} "{{ssh_command}}"`
2021-04-17 02:42:33 +01:00
- Forward a local port to a remote one, restarting when necessary:
`autossh -M {{monitor_port}} -L {{local_port}}:localhost:{{remote_port}} {{user}}@{{host}}`
2021-04-17 02:42:33 +01:00
- Fork `autossh` into the background before executing `ssh` and don't open a remote shell:
2021-04-17 02:42:33 +01:00
`autossh -f -M {{monitor_port}} -N "{{ssh_command}}"`
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:
2021-04-17 02:42:33 +01:00
`autossh -f -M 0 -N -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" "{{ssh_command}}"`
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:
`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:
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}}`