Imagine that you want access from local (your computer) to remote host 2. But you just have access from remote host 1 to host 2. Also you have access from localhost to host 1. So SSH Tunneling lets you use these connection to connect localhost to host 2. To create the SSH tunnel execute following in local machine.
ssh -L 9001:host2_IP:22 -N user@host1_IP -p5050
where: -N - do not execute a remote command, (you will not have the shell, see below)
-L Indicates that a local port forward is need to be created. The switch syntax is as follows.
-L <local-port-to-listen>:<remote-host>:<remote-port>
Now the SSH client at localhost will connect to SSH server running at host1_IP (running at port 5050) binding port 9001 of localhost to listen for local requests thus creating a SSH tunnel between host1_IP and localhost. At the host1_IP end it will create a connection to host2_IP at port 22. So localhost doesn’t need to know how to connect to ‘host2_IP’. Only localhost needs to worry about that.
Now it is possible to connect to host2_IP via ssh using this command:
shh localhost -p9001