Belgium

Automating SSH Tunnel establishment from SSH config file

In order to setup an ssh tunnel between port 8080 on the local machine and port 80 on the SSH server, you can go and type:

ssh -L8080:localhost:80 machine.example.org -l yourUsernameAtMachineDOTexampleDOTorg

But if you follow the law of the least effort, you won’t want to type that in everytime you need to establish the tunnel, you would rather type:

ssh tunnelName

and have SSH do everything by itself for you! This can be acomplished by inserting the following lines in your ~/.ssh/config file.

Host tunnelName        
User yourUsernameAtMachineDOTexampleDOTorg        
Hostname machine.example.org        
GatewayPorts yes        
LocalForward 8080 localhost:80

Notice the GatewayPorts yes directive, this is optional for the tunnel to come up but allows you to use the tunnel from other machines than just the one that establishes it!

Tags: ,

2 Responses to “Automating SSH Tunnel establishment from SSH config file”

  1. tanisha Says:

    Good way of telling, and pleasant piece of writing to get information about my presentation subject, which i am going to present in university.

  2. mt Says:

    Good Webpage, Carry on the useful work. Thanks a lot!|

Leave a Reply