There are times that I want to access to my computer in my laboratory remotely. However, it is inside the lab's internal network. Luckily, There is a gateway that I make a ssh connection to. The simplified scenario is shown below.
|---------| |-------| |-----------|
|my laptop|------|gateway|------|my computer|
|---------| |-------| |-----------|
To access my computer in the internal network, I can create a tunnel by running this command on my laptop:
ssh -L PORT:MY_COMPUTER_INTERNAL_IP:22 gateway -lUSER_TO_LOGIN_ON_THE_GATEWAY -N
This command will create a tunnel that will forward the local port PORT to my
computer port 22 (SSH). -N
is for not executing a remote command.
After that, I can simply ssh to my computer using the following command:
ssh -lUSER_TO_LOGIN_ON_MY_COMPUTER -pPORT localhost
And that's all.