Skip to content

Instantly share code, notes, and snippets.

@imposibrus
Created March 25, 2022 14:28
Show Gist options
  • Save imposibrus/96a42bf03c883675ea277df4688497f5 to your computer and use it in GitHub Desktop.
Save imposibrus/96a42bf03c883675ea277df4688497f5 to your computer and use it in GitHub Desktop.
Simple SSH-tunnel in SystemD
[Unit]
Description=Keeps a tunnel to 'server.com' open
After=network-online.target ssh.service
[Service]
# starting in user-mode:
User=user
ExecStart=/usr/bin/ssh -q -Nt -o ControlMaster=no -o ControlPath=/tmp/no -o ExitOnForwardFailure=yes -o ServerAliveInterval=15 -o ServerAliveCountMax=3 -p 22 -l user server.com -R 2224:127.0.0.1:22 -i /home/user/.ssh/id_rsa
# Restart every >2 seconds to avoid StartLimitInterval failure
RestartSec=90
Restart=always
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment