Skip to content

Instantly share code, notes, and snippets.

@samos123
Created June 27, 2016 06:41
Show Gist options
  • Save samos123/5a61461e8b9ceac919c7422844c0bfc0 to your computer and use it in GitHub Desktop.
Save samos123/5a61461e8b9ceac919c7422844c0bfc0 to your computer and use it in GitHub Desktop.
/etc/systemd/system/reverse-ssh-tunnel.service to keep a reverse ssh tunnel restarted automatically
[Unit]
Description=Phone Home Reverse SSH Service
ConditionPathExists=|/usr/bin
After=network.target
[Service]
User=sshtunnel
ExecStart=/usr/bin/ssh -NTC -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -i /home/sshtunnel/.ssh/id_rsa -R 22223:localhost:22 user@remote-ssh-server
# Restart every >2 seconds to avoid StartLimitInterval failure
RestartSec=3
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