SSHTunneling

ShscWiki :: LogIn :: PageIndex :: RecentChanges
Setting up a tunnel for all your applications through SSH is a simple and effective way to encrypt all of your network traffic. This can help foil someone on your school or work network running a packet sniffing program to snoop on you; it can also allow you to remotely access addresses only normally accessible from computers on the local lan. For instance, you can tunnel in to your home computer and then access your router configuration page without leaving it open to the web.

First, you have to run an ssh server on a computer that will stay connected to the internet. If you're using linux, you can get an open-source free ssh server here (http://www.openssh.com) If you're using windows, you can get one here (http://sshwindows.sourceforge.net)

Server Configuration


First you'll have to set them up. Chances are, if your linux distro is recent at all, you'll have ssh pre-installed. The INSTALL file in the tarball should guide you through the installation. If you're running NetBSD and some other security-minded unix flavors, you'll need to change the sshd_config file to allow tunnelling. Add or uncomment this line:
AllowTcpForwarding yes
After you do this, you'll need to get sshd to reread its config file. Type ps -C sshd or ps -C inetd (if you're using the internet super-server daemon for ssh connections) and note the process number. Now type kill -HUP <process number of the server>. This doesn't kill the process, but sends sshd a signal to reread its config file.

If you're on windows, just download the installer and follow the prompts. Next, set up user accounts. The process is detailed in the docs\quickstart.txt. Open a command prompt window, navigate to the install directory of OpenSSH (default is Program Files\OpenSSH), change to the bin directory, and then run two commands:
mkgroup -l >> ..\etc\group
mkpasswd -l -u <SOME USERNAME> >> ..\etc\passwd

After you're done with that, start the service by typing net start opensshd. Hopefully this works, if not check in the documentation for sshwindows (OpenSSH\doc) for help.


Now we need to set up your firewall or router to accept connections on port 22. Depending on the router, the method is different. Look for something labeled Port Forwarding, Gaming and Applications, or Virtual Servers. The port will be 22 and the address the internal IP of your ssh server.
If you have a firewall, you'll have to look up how to allow outside connctions in its documentation. Basically, allow connections from the outside on port 22.

Client Configuration


If that all went well, you're ready for client configuration. The steps here depend on the client you're using. This guide will start with PuTTY (http://www.chiark.greenend.org.uk/~sgtatham/putty/) a very full-featured ssh client for multiple platforms. I'll also explain how to use OpenSSH's ssh client. PuTTY first.

Open up PuTTY and type the address of the server you're going to use. This'll be the address of your cable/dsl/etc modem if you're connecting from outside the lan, or the address of the computer running the ssh server if you're inside. The port should be 22 and the Protocol should be SSH. Don't hit Open yet though...


Next, click on the option under Connection - SSH named Tunnels. Type in 8080 in the Source Port box, and click the Dynamic radio button. The port can be any value, but we'll use 8080 in the example. You can leave the Destination box blank, as it is ignored for Dynamic forwarding. Click the Add button, and you should see D8080 appear in the Forwarded Ports: list.


Now hit the Open button at the bottom. You should get a warning asking you whether you want to add an RSA key to the registry. Press yes, and wait for the login as: prompt to appear. Type the username you used in the mkpasswd -u <USERNAME> step. You will use your windows login password. Once you are logged in, you can use the port.


Browser Setup


Now, on to how you use this new SOCKS 5 server you have. There are a multitude of ways, so I'll show you how to set up IE and Firefox to use it.. You can also use it with any program that supports a SOCKS5 proxy. Simply use localhost as the server and 8080 (or whatever port you forwarded) for the port.

For IE:


1) Go to Tools->Internet Options->Connection Tab
2) At the bottom, in the Local Area Network (LAN) settings section, press the LAN Settings... button. Check the box that says Use a proxy server for your LAN (these settings will not apply to your dial-up or VPN connections, but leave the two boxes beneath it blank.
3) Press the Advanced... button, and in the Socks: field, type localhost for the address and 8080 (or whatever you used) as the port.
4) Press OK on all these dialogs and try navigating to a webpage to test.


For Firefox:


1) Go to Tools->Options and select the General tab
2) At the bottom, in the Connection section, click the Connection Settings... button.
3) Click the Manual proxy configuration radio button and input localhost in the SOCKS Host: section, 8080 (or whatever you used above) in the port section.
4) Hit ok on all the dialogs and try navigating to a webpage to test.
- Note: The settings screen may differ depending on the theme/skin you're using.

This article is ©2010 by the respective authors. Reproduction is prohibited without express permission from all contributors.