This guide explains how to create a persistent SSH reverse tunnel using systemd without relying on tools like autossh. This approach automatically restarts the SSH tunnel if it fails or gets stuck due to disconnections.
Using systemd provides several benefits over standalone SSH or autossh:
- Automatic Restart: If the SSH connection fails,
systemdrestarts it automatically. - Keep Alive: Prevents stale SSH connections by using SSH's
ServerAliveIntervalandServerAliveCountMax. - Clean and Simple: Avoids external tools and manages the service with native system management.