Last active
August 16, 2021 17:56
-
-
Save ginkgomzd/4a900544c04808927a22d1f2615bb922 to your computer and use it in GitHub Desktop.
SSH Proxy Tunnel Example
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
# bring up the ssh tunnel without requiring leaving a terminal open | |
# by opening a connection without a shell with the -N option. | |
# nohup helps to keep open the connection. | |
# provide an optional log, which might help troubleshooting. | |
# combine stderr and stdout( 2>&1 ) | |
# send to background ( & ) | |
connect() { | |
nohup ssh tunnel -N > ~/.tunnel.log 2>&1 & | |
} |
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
# | |
# The ssh host that is allowed to connect to the target | |
# Set any credentials you need here, like username and id file... | |
# | |
Host proxy.example.org | |
User me | |
ForwardAgent yes | |
# | |
# the ssh config that sets up forwarded ports through the proxy | |
# Configs should match what the target server expects. | |
# The ProxyCommand, does the magic. Configure different credentials, if needed on your proxy host config. | |
# | |
Host tunnel | |
HostName target.example.org | |
User me | |
IdentityFile ~/.ssh/id_rsa | |
ProxyCommand ssh -W %h:%p proxy.example.org | |
LocalForward 33891 target.example.org:22 | |
LocalForward 8081 target.example.org:80 | |
# | |
# OPTIONAL: | |
# If you were to get a shell on the target, | |
# create this entry that points to localhost and the port you are forwarding | |
# on the proxy host config. | |
Host target | |
HostName localhost | |
Port 33891 | |
User me | |
IdentityFile ~/.ssh/id_rsa | |
ForwardAgent yes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment