Wiki > SSH Tunneling
SSH tunneling allow you to securely route traffic through your slot using an encrypted tunnel. SSH tunnels can be used to prevent network monitors on your local network from monitoring what sites you visit, or to bypass overly restrictive web filters. They are also useful for trackers that require users to log in from an IP before being able to seed from it.
Creating an SSH tunnel
Windows
Since Windows does not come with an SSH client, you will need to download and install KiTTY. The first time creating a tunnel you will need to create a Saved Session, which you will be able to reuse later:
- Install and open KiTTY
- Enter
server.whatbox.ca
in the Host Name field - Make sure SSH is selected as the connection type
- In the menu on the left, go to Connection->Data.
- Enter your Whatbox username and password in the Auto-login username and Auto-login password fields.
- In the category menu on the left, expand Connection' Then expand SSH and select Tunnels.
- Next to Source port enter
8080
- Select Dynamic. Click Add
- (Optional) In the menu on the left, go to Window->Behavior. Check the Send to tray on startup if you would like the KiTTY window to hide in your system tray after it is connected.
- (Optional) In the menu on the left, go to Connection. Enter
150
next to Seconds between keepalives. On the same page, check Attempt to reconnect on connection failure. These settings will help maintain your connection in the event of an unstable local network. - In the category menu on the left, select Session to go back to the first screen.
- Under Saved Sessions enter
Whatbox Proxy
and click Save to save all settings.
To start the tunnel:
- Open KiTTY
- Under Saved Sessions double-click Whatbox Proxy
- If all went correctly you should now see
user@server ~ $
To automatically start the tunnel on Windows startup:
- Open your Start Menu. Find the Startup folder in All Programs
- Right-click on Startup and choose Open. The folder will open in Windows Explorer.
- Right-click in the empty space and choose New->Shortcut
- Hit the Browse button and navigate to where you installed KiTTY.
- Select
kitty.exe
and hit OK - Click Next and enter
Tunnel
in the text box. - Click Finish when done.
- Now Right-click on the
Tunnel
shortcut and select Properties - In the Target box, add
-load "Whatbox Proxy"
to the end. - If it looks similar to
"C:\Program Files\Kitty\kitty.exe" -load "Whatbox Proxy"
, hit OK. You are done.
To disconnect the tunnel:
- Type
logout
- Press
Enter
Linux and macOS
- Open a terminal
- Enter the following command:
ssh -ND 8080 user@server.whatbox.ca
Explanation:
-N
hides the output from the SSH connection. It is optional. If you wish to use the SSH connection to run commands on the server as you normally would, remove the N
switch.
-D 8080
creates a dynamic port, in this case 8080, on your local computer. This is how your browser, or other software, will connect to the tunnel.
Advanced users who tend to keep a tunnel open for long periods of time might wish to look into additional options:
-f
is an extra optional argument that causes ssh to run in the background after it's successfully established a connection, which may be more preferable in some cases than keeping the tunnel running interactively.- adding
-o TCPKeepAlive=yes
and-o ServerAliveInterval=30
will help the connection remain open by periodically sending keep-alive packets. On some platforms this also helps detect transient connection issues between you and your slot earlier so it may exit sooner, which is useful if you run it under something likesupervisord
which can restart it upon failure. - autossh is an alternative tool built for SSH tunneling that performs simple periodic checks to make sure the tunnel is still functional and responsive.
Note that automating your tunnel usually will require automated authentication of some form; you will need something to enter your password, or if you've added an SSH public key to your slot to enable key-based authentication, it will need to know where to find the private key (it may also need your key's passphrase, if you set one).
Using As a Browser Proxy
Firefox
- Create and start your SSH tunnel
- Open Preferences, found either in the Edit or Tools menu
- Select the Advanced section and click the Network tab
- Under Connection click the Settings button.
- Select Manual proxy configuration
- Next to SOCKS Host enter
localhost
and8080
as the port. - Select SOCKS v5
- In the No Proxy For box remove
localhost
from the list if it's written there. - Click OK, then Close
The proxy will be functional at this point. It is recommended that you also set Firefox to send DNS requests over the proxy as well:
- Browse to
about:config
- Click I'll be careful, I promise
- Type in
network.proxy.socks_remote_dns
and press Enter. - Toggle the value to True by either double-clicking the listed row, or right-clicking and selecting Toggle.
Linux: Google Chrome and Chromium
- Create and start your SSH tunnel
- Open Preferences
- Select Under the Hood
- Next to Network click Change Proxy Settings...
- Select Manual Proxy Configuration
- Next to Socks host enter
localhost
and8080
as the port. - Click Close
Windows: Internet Explorer, Google Chrome, Opera, and Safari
- Create and start your SSH tunnel
- Open the Windows Control Panel
- Open Internet Options
- Select Connections
- Select LAN settings
- Check Use a proxy server for your LAN and click the Advanced button.
- In the boxes next to Socks: enter
localhost
and8080
as the port. Leave all the other fields blank. - Click OK, OK, OK
macOS: Google Chrome and Safari
- Create and start your SSH tunnel
- Select System Preferences >> Network >> Advanced >> Proxies
- Check checkbox next to SOCKS Proxy
- Under SOCKS Proxy Server, enter
localhost
and8080
as the port. Leave all the other fields blank. - Click OK, Apply
Proxying Other Programs
In the same way that you can proxy your web browser's traffic, you can also tunnel any other program that has support for a SOCKS proxy.
For example, if you wanted to tunnel your local installation of uTorrent, you can just fill out the fields in the Connection category of the program's settings appropriately:
If the program you're using does not support native SOCKS proxies, it is possible to add support for this with tsocks.
Selectively Tunneling URLs
This is an example of a proxy.pac file:
function FindProxyForURL(url, host) {
if (shExpMatch(url, "*whatsmyip.org*")) { return "SOCKS localhost:8080"; }
// direct for everything else
return "DIRECT";
}
- Create a proxy.pac file which has a SOCKS line for each host you wish to proxy
- In your proxy settings, input the location of the proxy.pac file as your autoconfiguration URL.
file:///home/username/proxy.pac
- You will only be able to browse urls which match a SOCKS rule when your ssh tunnel is up.