Skip to content

Instantly share code, notes, and snippets.

@guettli
Created December 22, 2017 11:40
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save guettli/31242c61f00e365bbf5ed08d09cdc006 to your computer and use it in GitHub Desktop.
Save guettli/31242c61f00e365bbf5ed08d09cdc006 to your computer and use it in GitHub Desktop.
Reliable persistent SSH-Tunnel via systemd (not autossh)
# Reliable persistent SSH-Tunnel via systemd (not autossh)
# https://gist.github.com/guettli/31242c61f00e365bbf5ed08d09cdc006#file-ssh-tunnel-service
[Unit]
Description=Tunnel for %i
After=network.target
[Service]
User=tunnel
ExecStart=/usr/bin/ssh -o "ExitOnForwardFailure yes" -o "ServerAliveInterval 60" -N tunnel@%i
Restart=always
RestartSec=5s
StartLimitInterval=0
[Install]
WantedBy=multi-user.target
@rolfen
Copy link

rolfen commented May 7, 2018

Thank you!

@stokito
Copy link

stokito commented Jul 8, 2023

Please check out my systemd service https://github.com/yurt-page/sshtunnel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment