Skip to content

Instantly share code, notes, and snippets.

@bonnee
Last active January 29, 2022 10:44
Show Gist options
  • Save bonnee/f78f25fc44413fbadbe26a3dd12a2149 to your computer and use it in GitHub Desktop.
Save bonnee/f78f25fc44413fbadbe26a3dd12a2149 to your computer and use it in GitHub Desktop.
Systemd service file to keep an ssh reverse tunnel open
[Unit]
Description=Keeps a tunnel to home open
After=network.target
[Service]
User=<username>
# -p [PORT]
# -l [user]
# -M 0 --> no monitoring
# -N Just open the connection and do nothing (not interactive)
# LOCALPORT:IP_ON_EXAMPLE_COM:PORT_ON_EXAMPLE_COM
ExecStart=/usr/bin/ssh -g -NC -tt -o "ServerAliveInterval=10" -o "ExitOnForwardFailure=yes" -o "StrictHostKeyChecking=no" -R <local_port>:127.0.0.1:22 <local_user>@<public_ip> -p 8481
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment