Tuesday, November 8, 2011

Create an SSH Tunnel

Sometimes it is necessary to create a tunnel in order to access a port on a remote box from your local box and there is a firewall preventing you from reaching it.  As long as you have access to SSH, you can access this port.  In order to do so, just use the following command:

ssh -N user@remote-server -L localport/localhost/remoteport


The -N switch is used so commands are not executed on the remote system.  Now, if you are having issues keeping the tunnel open due to lack of traffic, you can change the line to the following:

ssh -N user@remote-server -o ServerAliveInterval=15 -L localport/localhost/remoteport

This will then generate a heartbeat every 15 seconds so the tunnel will remain up.



No comments:

Post a Comment