Keep SSH Tunnels Alive With autossh

Automatically restart an SSH port forward when the connection drops.

LinuxsshnetworktunnelLow risk
Run autossh -M 0 -N -L 8080:localhost:80 user@host to maintain a local forward.

01Command

Command
$ autossh -M 0 -N -L 8080:localhost:80 user@host

02What it does

autossh supervises an ssh process and restarts it when the connection fails, which is essential for long-lived tunnels. The -M 0 disables the legacy monitoring port and relies on ssh's own ServerAlive options.

03Risk

RiskLow risk
Requirementssudo apt install autossh
!Warning: An always-on tunnel widens the attack surface; restrict keys with command= and no-pty where possible.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • Debian package: autossh
    Debian · vendor-doc · 2026-09-20
    Evidence: Debian packages autossh, which monitors and restarts SSH sessions and tunnels.
  • autossh
    Official project · vendor-doc · 2026-09-20
    Evidence: Debian packages autossh, which monitors and restarts SSH sessions and tunnels.

Last verified: 2026-09-22 · Category: Network

06Related solutions