Last active
May 30, 2017 21:45
-
-
Save mendhak/ad77bddcecb344d027ba6d29134c8c96 to your computer and use it in GitHub Desktop.
Reliable methods of creating SSH tunnels for TCP forwarding
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
#Source: https://stackoverflow.com/questions/2241063/bash-script-to-setup-a-temporary-ssh-tunnel | |
#SSH feature - control sockets | |
ssh -4 -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa -M -S my-ctrl-socket -fnNT -L 10023:remoteserver.com:8000 dev@middleserver.internal | |
#Get PID - you'll have to parse this | |
ssh -S my-ctrl-socket -O check dev@middleserver.internal | |
#Exit | |
ssh -S my-ctrl-socket -O exit dev@middleserver.internal | |
#------------- | |
# Another way without control sockets | |
ssh -4 -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa -Cfo ExitOnForwardFailure=yes -NL 10023:remoteserver.com:8000 dev@middleserver.internal | |
PID=$(pgrep -f 'NL 10023') | |
[ "$PID" ] || exit 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment