SSH Tunneling

Hi Folks,

From now on I will need to use the SSH by tunneling to connect from my Home machine (Client) to my Office machine (Server) through a SSH Gateway because my Office machine is not directly connected to the Internet anymore, it seems a little bit complicated but I will try to simplify the things.

First of all the scheme to guide those who still may not have understood:

To access/connect the server I want, I can do by 2 ways:

    1. Connect to the SSH Gateway and then, connect to the desired server, it is the simplest solution but become quite costly and annoying when you need the SSH or SCP often, especially the SCP because you must copy to a tmp directory of the SSH Gateway all the files you want and then copy to desired server.


    1. Open a port in the client machine that connects to the desired server directly by tunneling, may seem more complicated but worth it. I will show how to do it bellow.


How to open the tunnel:

ssh -p <SSH_port_in_SSH_gateway> -fN -L <Port_to_use_in_client_machine>:<Server_IP>:<SSH_port_in_Server> <user>@<SSH_Gateway_IP>



ssh -p 22 -fN -L 6666: my_user@


How to use the tunnel – SSH:

ssh -p <Port_to_openned_in_client_machine> <user>@localhost



ssh -p 6666 my_user@localhost


How to use the tunnel – SCP:

scp -P <Port_openned_in_client> <user>@localhost:<file_to_be_coppied_in_server> <file_destination_in_client>


example 1 (copy from server):

scp -P 6666 my_user@localhost:/home/my_user/Desktop/foo /home/my_user/Desktop/


example 2 (copy to server):

scp -P 6666 /home/my_user/Desktop/foo my_user@localhost:/home/my_user/Desktop/


That’s it folks


Thanks to my friend Marcelo Gomes, who gave me the tips: Marcelo’s Blog (Blog in portugueses).

7 thoughts on “SSH Tunneling

  1. I keep listening to the news bulletin talk about getting free online grant applications so I have been looking around for the finest site to get one. Could you advise me please, where could i get some?

  2. Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! Its always nice when you can not only be informed, but also entertained! Im sure you had fun writing this article.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>