Created
August 5, 2025 19:18
-
-
Save sjmf/6ad576684fd12f59a6f8e969cfedb9cc to your computer and use it in GitHub Desktop.
Systemd configuration for persistent ssh reverse tunnel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Unit] | |
| Description=SSH tunnel service SSH on local port 22 to 22000 on remote host | |
| Wants=network-online.target | |
| After=network-online.target | |
| StartLimitIntervalSec=0 | |
| [Service] | |
| User=tunnel | |
| Group=tunnel | |
| Type=simple | |
| Restart=always | |
| RestartSec=60 | |
| ExecStart=/usr/bin/ssh -o UserKnownHostsFile=/home/tunnel/.ssh/known_hosts -o ExitOnForwardFailure=yes -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -NTR 22000:localhost:22 tunnel@example.com -i /home/tunnel/.ssh/id_rsa | |
| [Install] | |
| WantedBy=multi-user.target |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The remote address can be bound publicly using the bind:
-R *:22000:localhost:22, but this increases attack surface.Instead, one can use an SSH config (
.ssh/config) to bounce off localhost on the remote: