Belgium
Aug - 07

28

Automating SSH Tunnel establishment from SSH config file

Posted in General, Linux on August 28th, 2007 by Nicolas

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: ,