Last active
June 11, 2019 22:38
-
-
Save danry25/87f71f46b9e6c98969c6de44c10a8cd9 to your computer and use it in GitHub Desktop.
Automatic ssh tunneling using autossh & systemd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For using this on Debian & similar distros:
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 & serverBased on https://gist.github.com/ntrepid8/0af12c012dd2567c800799d86eb44f90