Skip to content

Instantly share code, notes, and snippets.

@caseyfw
Created August 28, 2018 11:31
Show Gist options
  • Select an option

  • Save caseyfw/c464f3f020ad7803576b08b05e2ee154 to your computer and use it in GitHub Desktop.

Select an option

Save caseyfw/c464f3f020ad7803576b08b05e2ee154 to your computer and use it in GitHub Desktop.
Reverse ssh tunnel systemd service
[Unit]
Description=Reverse SSH tunnel to scratch.
After=network-online.target
Before=multi-user.target
DefaultDependencies=no
[Service]
Restart=always
RestartSec=10
ExecStart=/usr/bin/ssh \
-i /etc/tunnel/id_rsa \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
-o ServerAliveInterval=20 \
-o ServerAliveCountMax=1 \
-o ExitOnForwardFailure=yes \
-N \
-T \
-R 2222:localhost:22 \
casey@scratch.caseyfulton.com
[Install]
WantedBy=multi-user.target
@caseyfw
Copy link
Copy Markdown
Author

caseyfw commented Aug 28, 2018

Runs as root, though you could set the user to something unprivileged and put an ssh key in an appropriate spot. -N means "don't run any commands", -T means "disable tty allocation".

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