- $LOCAL_HOST: 'localhost' or hostname from local network
- $LOCAL_PORT: open port on local machine
- $REMOTE_HOST: remote hostname visible from remote network
- $REMOTE_PORT: port on $REMOTE_HOST
ssh -L $LOCAL_PORT:$REMOTE_HOST:$REMOTE_PORT $USER@$SERVER
ssh -R $REMOTE_PORT:$LOCAL_HOST:$LOCAL_PORT $USER@$SERVER
Let's say I have a work computer and I can ssh to it from my home computer.
At work, there's a private(internal) network with our test server. test.privatenetwork.co
There's a CI app (jenkins) running on test.privatenetwork.co:8080
and I want to access it from my home computer.
Since I can't access it directly, as test.privatenetwork.co
is not visible to my DNS,
I will create a SSH tunnel.
So I type
ssh -L 8080:test.privatenetwork.co:8080 my_work_user@my_work_server
Which means "Make port 8080 on test.privatenetwork.co as seen from my_work_server available on localhost:8080"