Last active
January 26, 2022 03:53
-
-
Save mihow/30a41789da88d8d46f953ae9065234df to your computer and use it in GitHub Desktop.
Using SSH agent forwarding & bastion server / jump box
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
# Start SSH agent | |
eval $(ssh-agent) | |
# Add specific key | |
ssh-add ~/.ssh/butterfly.pem | |
# Add default key (if needed for GitHub, etc) | |
ssh-add | |
# SSH config entries | |
Host butterfly-bastion | |
Hostname 55.55.55.55 | |
User ubuntu | |
IdentityFile ~/.ssh/butterfly.pem | |
IdentitiesOnly yes | |
ForwardAgent yes | |
Host butterfly-dev | |
Hostname dev1.local | |
User ubuntu | |
ProxyJump ebutterfly-bastion | |
ssh butterfly-dev | |
# Auto start agent | |
if [ -z "$SSH_AUTH_SOCK" ] ; then | |
eval $(ssh-agent) | |
ssh-add | |
fi | |
# Auto stop agent | |
if [ -n "$SSH_AUTH_SOCK" ] ; then | |
eval `/usr/bin/ssh-agent -k` | |
fi | |
# Open SSH tunnel on from remote port 5432 to local port 5555 in background | |
# ssh -N -f -T -L 5555:butterfly-dev:5432 ubuntu@butterfly-dev |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment