SSH Tunneling

You can tunnel all of the traffic from your local box to a remote box that you have an account on using SSH. This is very useful to get around firewall restrictions.

ssh -g -f username@localmachine -i privatekey.pem -p 2222 -L 12345:remotemachine:56789 -N

The -g tells ssh to allow remote hosts to connect to local forwarded ports. The -f tells ssh to go into the background just before it executes the command. This is followed by the username and local machine you are logging into. If you use SSH key-based authentication to connect to your local box, use -i option to specify the private key. The -p option is used if your SSH is not running on port 22, so you need to specify it here. The -L 12345:remotemachine:56789 is in the form of -L local-port:host:remote-port. Finally the -N instructs OpenSSH to not execute a command on the remote system.

This essentially forwards the localmachine port 12345 to port 56789 on remotemachine over, with nice benefit of being encrypted. You can then simply connect to localmachine:12345 when you want to connect to remotemachine at port 56789.

Reference:
http://www.revsys.com/writings/quicktips/ssh-tunnel.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s