Skip to content

Instantly share code, notes, and snippets.

@chainq
Created February 2, 2025 12:43
Show Gist options
  • Save chainq/63e126a2c95b47bbbf00d3dfb23ee4b9 to your computer and use it in GitHub Desktop.
Save chainq/63e126a2c95b47bbbf00d3dfb23ee4b9 to your computer and use it in GitHub Desktop.
systemd service files for an SSH Reverse Proxy
# Put this into /etc/systemd/system
[Unit]
Description=Keeps a tunnel to %I open
After=network-online.target
# You can also run this as a specific user, change it below
[Service]
User=root
Environment="LOCAL_ADDR=localhost"
EnvironmentFile=/etc/default/ssh-tunnel@%i
ExecStart=/usr/bin/ssh -NT -o ServerAliveInterval=15 -o ExitOnForwardFailure=yes -R ${REMOTE_ADDR}:${REMOTE_PORT}:${LOCAL_ADDR}:${LOCAL_PORT} ${TARGET}
# Restart every >2 seconds to avoid StartLimitInterval failure
RestartSec=5
Restart=always
[Install]
WantedBy=multi-user.target
# This needs to go into /etc/default
# You then enable the service with "systemd enable ssh-tunnel@remote-example-http"
[email protected]
LOCAL_ADDR=localhost
LOCAL_PORT=80
REMOTE_ADDR=remote.example.host
REMOTE_PORT=64738
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment