Last active
August 29, 2015 14:20
-
-
Save aaronzirbes/12c3232fd7004e115650 to your computer and use it in GitHub Desktop.
SSHing throught a Jumphost
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 | |
host=${1} | |
domain=service.consul | |
environment=staging | |
#environment=prod | |
credprefix=mycompany | |
# IP address of jumphost | |
jumphost=12.34.56.78 | |
if [ "${1}" == "" ]; then | |
echo "You must supply a hostname" | |
exit 1 | |
fi | |
if [[ "${host}" == *.*.*.* ]]; then | |
echo "Detected IP" | |
else | |
echo "Detected Hostname" | |
host=${1}.${domain} | |
fi | |
credpath=~/.ssh/${credprefix}-${environment}.pem | |
sed -i -e "/${domain}/ d" ~/.ssh/known_hosts | |
echo "Connecting to jumphost ${jumphost}..." | |
echo "ssh -i ${credpath} -L 2222:${host}:22 -f -n ubuntu@${jumphost}" | |
ssh -i ${credpath} -L 2222:${host}:22 -f -n ubuntu@${jumphost} tail | |
echo "Connected to jumphost." | |
echo "" | |
echo "Connecting to ${host} through jumphost..." | |
echo "ssh -i ${credpath} -p 2222 ubuntu@localhost" | |
ssh -i ${credpath} -p 2222 ubuntu@localhost |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment