Skip to content

Instantly share code, notes, and snippets.

@erronjason
Created April 17, 2017 20:10
Show Gist options
  • Save erronjason/33dd2ff81eb883b043f4e99672fc6c1b to your computer and use it in GitHub Desktop.
Save erronjason/33dd2ff81eb883b043f4e99672fc6c1b to your computer and use it in GitHub Desktop.
Reverse SSH systemd service
# /etc/systemd/system/rssh.service
[Unit]
Description=Reverse SSH Service
ConditionPathExists=|/usr/bin
After=network.target
[Service]
User=<USERNAME HERE>
ExecStart=/usr/bin/ssh -NTC -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -i /home/<USERNAME>/.ssh/h -R <PORT YOU WANT OPEN ON REMOTE MACHINE>:localhost:<LOCAL SSH PORT> -l <REMOTE USERNAME> -N <REMOTE HOST> -p <REMOTE LISTENING PORT>
# 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