Created
March 3, 2018 23:40
-
-
Save sgdavis1/2d545278fc59c95721f05eb3aa40f519 to your computer and use it in GitHub Desktop.
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 | |
destport=$(echo $1 | awk -F ':' '{print $2}'); | |
desthost=$(echo $1 | awk -F ':' '{print $1}'); | |
tunnelhost=$2 | |
echo "Connecting to $1 via a tunnel through $2"; | |
if [[ $destport == "" ]]; then | |
destport=22; | |
echo "Assuming destination port is 22. Specify with 'host:port' if this isn't true..." | |
fi | |
if [[ $tunnelport < 1024 ]]; then | |
let "tunnelport=$tunnelport + 2000" | |
fi | |
echo "Executing: ssh -M -S tunnel-ctl-socket -fnNT -L $tunnelport:$desthost:$destport $tunnelhost" | |
ssh -M -S tunnel-ctl-socket -fnN -L $tunnelport:$desthost:$destport $tunnelhost | |
ssh -p $tunnelport localhost | |
echo "Executing: ssh -S tunnel-ctl-socket -O exit localhost" | |
ssh -S tunnel-ctl-socket -O exit localhost |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Easier way to connect to a host via a tunnel host when you are either using key auth, or can remember to type the passwords in order (tunnel / dest). Not super useful, but for whatever reason I feel it is easier to remember than trying to remember ssh tunneling syntax, haha.