# $LOCAL_IP: 'localhost' or machine from local network
# $LOCAL_PORT: open port on local machine
# $REMOTE_IP: remote localhost or IP from remote network
# $REMOTE_PORT: open port on remote site
# Forward Tunnel: map port from remote machine/network on local machine
ssh -L $LOCAL_PORT:$REMOTE_IP:$REMOTE_PORT $USER@$SERVER
# Reverse Tunnel: make local port accessable to remote machine
ssh -R $REMOTE_PORT:$LOCAL_IP:$LOCAL_PORT $USER@$SERVER
-
-
Save rkmax/d73b8110cede81c8e13fd5f673d93681 to your computer and use it in GitHub Desktop.
SSH Tunnel Cheat Sheet
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I love this cheat sheet. Thanks @rkmax for making this. I'm going to embellish this a little for people with less experience by adding some example values and other commands.
You can set the variables mentioned above (
$LOCAL_IP
,$LOCAL_PORT
, etc) with theexport
command:Note: I left out the dollar sign on purpose. You only use the dollar sign when you access the value of the variable.
The
LOCAL_IP
address will most likely have a value of 'localhost' as mentioned above. This can also be an IP address of a device on the local network.The
REMOTE_IP
is not the server address, it's the IP address local to the server address. You will probably want this set to 'localhost'. However, if theSERVER
address pointed to a computer (say, computer A) that had computer B in its local network, you could set it to the local IP address of computer B on computer A's local network (Ex: 192.168.1.X or 10.0.0.X) and you could access ports from computer B.The
REMOTE_PORT
is not the SSH port on the server, it's the port you want to forward to theLOCAL_PORT
. If you need a custom SSH port (other than 22), you'll need to add-p <port_number>
to the end of the commands in this cheat sheet.