Created
March 12, 2021 08:30
-
-
Save erm3nda/46ee9d22d416c2a65b87f1ee5d8ef4d7 to your computer and use it in GitHub Desktop.
SSH permanent tunnel service
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
#Template SystemD service for a auto healing (reverse) SSH tunnel. | |
#Place this to /etc/systemd/system/ folder. | |
#Edit all values inside <> | |
#/etc/systemd/system/ssh-persistent-tunnel.service | |
#Edit the ports, remote user+host, and the key file. | |
#In the authorized_keys file on the other system, use something like this: | |
#<restrict,command="echo 'No Commands Allowed.'",port-forwarding,permitopen="localhost:22",permitlisten="localhost:5000"> | |
[Unit] | |
Description=SSH Persistent Tunnel | |
After=network-online.target | |
[Service] | |
ExecStart=/usr/bin/ssh -T -N -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o ExitOnForwardFailure=yes -R <1234:localhost:22> <root@localhost> -o IdentityFile=</home/user/.ssh/id_rsa> | |
ExecStop=/bin/kill -HUP $MAINPID | |
ExecReload=/bin/kill -HUP $MAINPID | |
Restart=on-failure | |
RestartSec=60 | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment