How To: Surf Securely with an SSH Tunnel

May 16, 2008 · 32 comments

By the time most people read this post I will have stayed in three different hotels in New York, New Jersey and Maryland while trekking along with Challenge X teams for their final competition. That means I have had a chance to glance through several terms of service agreements for various hotel internet connections. They usually include some clause stating that they retain the right to monitor your online activities and so on – Orwellian Big Brother stuff. The same generally goes for places that have free or for-pay Internet connections. Although, with unsecured Wi-Fi Internet connections it’s more an issue of other users sniffing your data with network analyzer tools like Wireshark.

If you’re paranoid about those types of privacy and security issues and you happen to have access to a server with SSH, you can securely send your Internet data through your server in an encrypted network tunnel. SSH tunnels are nothing new and there are many ways of setting them up, even standalone applications that can do it for you. You can even setup specific tunnels for different ports, such as for securing your email. For now, I’m just going to deal with securing HTTP traffic.

Tools

I’m doing this on my Mac, but you essentially just need terminal access. (However, configuring your browser to work with the SSH tunnel will vary.) If you’re on Windows, there is always PuTTY.

Fire up a terminal session and enter in the long SSH command below. Naturally, change out the username and domain info for the server you’re using.
ssh -D 8080 -f -C -q -N myuser@myserver.com

If you want to find out the specifics of those flags, the ssh man page gives a good rundown. The 8080 number is the port that I will be sending traffic through instead of the regular HTTP port 80. You can pretty much use any port number, but port 8080 is the standard HTTP alternate as defined by the IANA (interesting link nonetheless).

Config

If prompted for a password, enter it. The SSH tunnel is now active, barring any errors. Now you just need to get your browser to use it. For Safari this is a very simple process. Head over to System Preferences » Network » Advanced » Proxies. Click the checkbox next to SOCKS Proxy, supply “localhost” with port 8080 for the server and click OK, then Apply.

Configuring SOCKS Proxy in OS X Leopard

The changes should be automatic in Safari. You can check by visiting a site like What’s My IP. You’re good to go if it displays the IP address of your server, not your computer.

How often do you use networks you don’t trust? How do you deal with them?

PaulStamatiou.com runs on the Thesis Theme for WordPress

How smart is your Theme?  How good is your support? Check out ThesisTheme for WordPress.

Thesis is the search engine optimized WordPress theme of choice for serious online publishers. If you’re a blogger who doesn’t understand a lot of PHP, Thesis will give a ton of functionality without having to alter any code. For the advanced, Thesis has incredible customization possibilities via Thesis hooks.

With so many design options, you can use the template over and over and never have it look like the same site. The theme is robust and flexible enough not only to accommodate a site like PaulStamatiou.com, but also to enable the site to run far more efficiently than it ever has before.

{ 7 trackbacks }

Review: Meerkat (SSH Tunnels Made Easy) - PaulStamatiou.com
June 28, 2008 at 11:05 pm
…My heart’s in Accra » Nosethumbing and internet censorship
July 30, 2008 at 3:06 pm
…My heart’s in Accra » Internet Censorship and Nose-Thumbing
July 30, 2008 at 3:09 pm
PDF downloads made easy in Firefox and more! | Fading Whispers: The Chronicles
August 30, 2008 at 10:17 am
Anonymize Your Web Traffic with JanusPA - PaulStamatiou.com
December 24, 2008 at 2:43 am
Zend Studio (Eclipse) Remote Editing through a secure proxy
August 31, 2009 at 11:47 am
How To/Review: Surf Securely with VyprVPN — PaulStamatiou.com
January 14, 2010 at 10:13 pm

{ 25 comments… read them below or add one }

1 Timothy Andrew May 16, 2008 at 1:45 am

Okay, just to clarify. The -D 8080 forwards local port 8080 to port 8080 on your remote server, right?

So localhost:8080 would be forwarded to remoteserver:8080?

Reply

2 AJZ May 16, 2008 at 3:25 am

Timothy,

The -D option is a dynamic forward, which means ssh acts as a SOCKS proxy and takes things directed at localhost:8080 and forwards them through to the server, where the ssh server will make and handle the request and return it to your machine.

If you want to forward just a single local port to the remote server, you would use “-L localport:127.0.0.1:serverport”.

Reply

3 Michele May 16, 2008 at 4:22 am

Sounds great! Never thought of this…thanks for sharing… :)

Reply

4 Jim Whimpey May 16, 2008 at 5:14 am

I’d never considered trying this before because I thought it’d be too difficult and may not work anyway. I’m in Australia and now I’m using it to watch Hulu videos which is amazing but even better I can watch NHL games live on Yahoo Live Sports and CBC online. This has completely changed my world! Thank you thank you thank you!

Reply

5 Ben Mitchell May 16, 2008 at 5:53 am

On Mac OS X, network location support is handy for streamlining the SOCKS configuration process. I typically set up a network location for SSH forwarding that has proxy port information configured, that way switching to it is a breeze.

In System Preferences &rlquo; Network, select “Edit Locations…” from the location dropdown at the top of the preference pane. Add a new location with whatever name you please, click “Done,” and then select the new location. From there, follow Stammy’s instructions.

Once you have multiple network locations configured, a new Apple Menu submenu appears listing them. Just select the location you want from there. For Quicksilver and LaunchBar users, they can also be used to change network locations.

The only applications I’ve run into that don’t obey Mac OS X’s built-in proxy settings are Mozilla applications and Unix ports (most anything installed from Fink or MacPorts, for instance). These have to be configured manually, regardless of whether you’re using a separate network location or not.

Reply

6 Dean May 16, 2008 at 6:38 am

cue nosebleed.

Reply

7 Blake Brannon May 16, 2008 at 7:56 am

Here is an article I wrote explaining how to do this with Portable Apps (Also Windows). http://www.blakebrannon.com/2007/07/22/securely-surf-the-internet-on-a-remote-network-via-ssh/

Reply

8 Mark Nichols May 16, 2008 at 9:06 am

Douglas Bowman published an excellent guide to using ssh to secure email transmitted over a wireless connection. I’ve been using his method for the past three years without fail and without any issues.

http://www.stopdesign.com/log/2005/02/07/secure-email.html

Reply

9 Bill O'Neill May 16, 2008 at 11:03 am

I’ve been using ssh tunnels to a squid http proxy I run at home. Then using http://foxyproxy.mozdev.org/ I can selectively pick what content I want run through there.

Reply

10 Daniel Andrade May 16, 2008 at 1:00 pm

Nice post paul! Are you using it with MediaTemple?

Reply

11 Ben K. May 16, 2008 at 6:32 pm

I’m using Firefox to do this but make sure that Safari or whatever browser your using can use your remote SSH server as remote DNS. If you don’t then whoever is monitoring your connection will know exactly where you are browsing based on the local DNS requests. I thought I was completely safe until I fired up ethereal and saw my DNS requests going to the local server.

For Firefox:

1. Browse to “about:config”
2. Type “dns” in the filter field
3. Look for “network.proxy.socks_remote_dns” and set the value to “true”
4. Restart Firefox just to be safe and surf away!

Reply

12 Dean May 17, 2008 at 4:09 am

Hey, Paul, I think your site had some downtime earlier. Well, it could’ve been my connection, but…

Reply

13 James Cassell May 17, 2008 at 9:51 pm

I do this all the time, though for different reasons. For some reason, my university blocks outgoing SMTP, so I just tunnel through with SSH. It works pretty well.

Reply

14 Steve May 23, 2008 at 8:09 am

Great resource. After fumbling with free SOCKS this works great. For some reason ftp would stall to my MT server, something the MT techs could never fix nor really work out why it would be happening.

After trying this, Transmit is no longer stalling.

Reply

15 peter July 4, 2008 at 8:01 am

You may also test privacy of internal IP address this way:

open -a Safari http://www.auditmypc.com/software_audit.asp

( http://codesnippets.joyent.com/posts/show/1326 )

Reply

16 Thomas October 6, 2008 at 8:56 am

Hi, please note that this is not completely secure. Check http://www.auditmypc.com/anonymous-surfing.asp, which will still be able to see your true IP number. If I understand this correctly, one can only be safe if one disables all Javascript/Java ability and thus loose the respective functionality. With those enabled, however, scripts telling a true identity can be run on your local computer. Beware.

Thanks for this information anyway, because in many cases this is enough to get access to local systems etc.

All the best,

Thomas

Reply

17 Thomas October 6, 2008 at 9:07 am

Hi, sorry, I found a mistake in my setup, now it seems to work. The checking routines of the website provided in my previous message is happy now. Sorry to have bothered you unfoundedly, but maybe that address is useful. Thomas

Reply

18 Tim Fletcher December 31, 2008 at 2:23 pm

This is simply awesome. Now I can actually make use of the 99.5% unused bandwidth my server has each month and finally use Pandora/Hulu/Netflix etc!

Just a note that if you’ve changed the SSH port (for security reasons), you’ll need to add that in. Like this

ssh -D 8080 -f -C -q -N -p XXXXX myuser@myserver.com

Reply

19 John Smith January 8, 2009 at 4:44 pm

Does this last until you restart your mac?

Reply

20 Jacob January 10, 2009 at 6:19 pm

As long as you are keeping the SSH session open.

Reply

21 Randy January 18, 2009 at 11:30 am

Has anyone done this on a PC with Putty via MediaTemple and Firefox?

Reply

22 Daniel Andrade January 27, 2009 at 4:33 pm

Randy, yes, me

Reply

23 Randy January 27, 2009 at 4:35 pm

Daniel… Figured it out. Man its sweet to be able to do this from…work. ;)

Reply

24 esck March 13, 2009 at 9:24 pm

is this something that could be against our host ToS?

I’ve been using this trick and proxifier to access US restricted sites like hulu.

:)

Reply

25 Steve March 14, 2009 at 8:59 am

It also might be useful for OSX users to set up a shell alias to save you having to type out the terminal command every time. Check out here for a good howto: http://hayne.net/MacDev/Notes/unixFAQ.html#shellAliases

Reply

Leave a Comment

You can 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>

Previous post:

Next post: