Skip to content

Instantly share code, notes, and snippets.

@nizhib
Created June 19, 2021 10:45
Show Gist options
  • Save nizhib/0956bd7a03f6f3356566295bd2fc7cab to your computer and use it in GitHub Desktop.
Save nizhib/0956bd7a03f6f3356566295bd2fc7cab to your computer and use it in GitHub Desktop.
SSH Tunnel Service
[Unit]
Description=Keeps the ssh tunnel to %i open
After=network.target
[Service]
User=nizhib
Environment="AUTOSSH_PORT=0"
Environment="AUTOSSH_LOGFILE=/tmp/tunnel.%i.log"
Environment="AUTOSSH_PIDFILE=/tmp/tunnel.%i.pid"
Environment="SSH_OPTIONS=-o 'ServerAliveInterval=60' -o 'ServerAliveCountMax=3'"
PIDFile=/tmp/tunnel.%i.pid
# -f drop to the background before running ssh
# -N do not execute a remote command
# -T disable pseudo-terminal allocation
# -q quiet mode
# -R port:host:hostport
# -i identity_file
# -l [user]
# -p [PORT]
ExecStart=/usr/bin/autossh -f -N -T -q -R 9022:localhost:22 -i /home/nizhib/.ssh/tunnel -l nizhib %i
# RestartSec=5
# 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