Skip to content

Instantly share code, notes, and snippets.

@danry25
Last active June 11, 2019 22:38
Show Gist options
  • Save danry25/87f71f46b9e6c98969c6de44c10a8cd9 to your computer and use it in GitHub Desktop.
Save danry25/87f71f46b9e6c98969c6de44c10a8cd9 to your computer and use it in GitHub Desktop.
Automatic ssh tunneling using autossh & systemd
[Unit]
Description=AutoSSH reverse tunnel service for remoteserver 6667 -> 22
After=network.target
[Service]
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/autossh -M 0 -o "ExitOnForwardFailure=yes" -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -NR 6667:127.0.0.1:22 user@remoteserver -i /root/.ssh/id_ed25519
[Install]
WantedBy=multi-user.target
@danry25
Copy link
Author

danry25 commented Jun 2, 2019

For using this on Debian & similar distros:

ssh-keygen -t ed25519 && apt install autossh

Copy the SSH key to the remote server, eg: ssh-copy-id user@remoteserver
Create this file at /etc/systemd/system/autossh-jump-rtunnel.service and update line 7 from user@remoteserver to the correct user & server

systemctl enable autossh-jump-rtunnel.service
systemctl start autossh-jump-rtunnel.service

Based on https://gist.github.com/ntrepid8/0af12c012dd2567c800799d86eb44f90

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