Skip to content

Instantly share code, notes, and snippets.

@aaronzirbes
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronzirbes/12c3232fd7004e115650 to your computer and use it in GitHub Desktop.
Save aaronzirbes/12c3232fd7004e115650 to your computer and use it in GitHub Desktop.
SSHing throught a Jumphost
#!/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