Created
December 23, 2017 00:40
-
-
Save duk3luk3/94aa449a7668cf549ecb79bdc8a52901 to your computer and use it in GitHub Desktop.
Persistent SSH Tunnel
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
check host ssh_tunnel with address 127.0.0.1 | |
IF FAILED host 127.0.0.1 port 19999 PROTO SSH | |
with timeout 20 seconds for 2 cycles | |
then alert |
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=SSH Reverse tunnel | |
[Service] | |
Type=simple | |
Restart=always | |
RestartSec=60 | |
ExecStart=/usr/bin/bash -c /path/to/ssh_tunnel.sh | |
User=USER | |
Group=systemd-journal | |
[Install] | |
WantedBy=network.target |
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
#!/bin/bash | |
# The SSH endpoint to connect to | |
ADDR=username@example.com | |
# A SSH Key for the endpoint | |
IF=/path/to/key/id_rsa | |
while true; do | |
# ssh with Keepalive and -R reverse port forwarding | |
ssh -i $IF -o "ServerAliveInterval=60" -o "ExitOnForwardFailure=yes" -R 19999:localhost:22 $ADDR -N | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment