Monday, January 13, 2014

SSH tunnelling

Currently, I wanted to ssh to a remote server from my computer. But, the network where my computer resides has blocked the ssh port. I could not do it the normal way. So, I used the SSH tunnelling technique  to bypass this strictly policy.

Here is how I did it:

1. Create a SSH tunnel from my machine (localhost) through a un-blocked server (e.g. the firewall), the only computer that can make ssh connections with outside world, to the server I want. (Luckily, I have access to the firewall of the network)

$ ssh -L

This will ask me to provide the password of the firewall_user. It will open a tunnel from my local machine at port 2022 to the ssh port (22) of the firewall. Keep the terminal window open and move on the next step.

2. Open another terminal window and SSH through the tunnel by the following command:

$ ssh -l remote_user -p 2022 localhost

This command will ask me password of the remote_user user in the, (but @localhost, because we connect through the tunnel):

remote_user@localhost's password:

And then I have access to the remote server's shell, beautifully! \m/