I noticed something spiffy about the wicd network manager today, it has a section that allows you to trigger scripts at certain points of the connection process.. specifically interesting to me were post-connect and post-disconnect.
For a long time I've been trying to tell people that if at all possible they should tunnel their wireless traffic through an ssh connection whenever possible if they are on a public or insecure wifi. The problem with this is twofold, the first is that not everyone has access to a machine that they can use as an ssh tunnel exit point, and the second is that they have to open a terminal and manually set up the connection.. anything that takes effort like that, people are likely to forget or not bother with. I cant help people who have no publicly accessible Unix shell, but for those that do we can make having an available ssh tunnel a constant option.
So! enter wicd and its automatic script launching on connect... we'll set up a public key authorization login on the ssh server, write a tunnel script that will run in the background, and simply tell wicd that any-time we connect to the wireless to run the script.
For those unfamiliar with Public Key Authentication:
it is an ssh authentication method that uses a generated rsa certificate rather than a password, effectively creating a trust between the account on your laptop and the account on the server (never do this with root, and for this you don't even need to use an account that has sudoer access).
On your client machine (your laptop), run the following
$ssh-keygen -q -f ~/.ssh/id_rsa -t rsa
$chmod -R 700 ~/.ssh
$scp ~/.ssh/id_rsa.pub my.sshserver.org:
On the server account run these
$mkdir ~/.ssh
$mv id_rsa.pub ~/.ssh/authorized_keys
$chmod 700 ~/.ssh
$chmod 600 ~/.ssh/authorized_keys
Finally, back on the client side open an ssh connection as follows:
$ssh -o PreferredAuthentications=publickey my.sshserver.org
As for the ssh connection script..
I like to have a /scripts folder where i drop any tools i make myself, especially oneliners like this, so i recommend making a new file in /scripts called ssh_tunnel.sh, which will consist of two whole lines.
$vim ssh_tunnel.sh
#!/bin/bash
ssh -f -N -D9999 -i /home/username/.ssh/id_rsa username@my.sshserver.org
This creates an ssh tunnel that is listening on localhost port 9999 (-D), expects no further commands (-N), and is forked to the background (-f), to my ssh server out on the internets. Also, since we setup public key authentication, it wont prompt for a password.
Any program now that allows proxying, such as a webbrowser, I can point at 127.0.0.1 on port 9999 and it will push all of the traffic through the encrypted connection.
And finally, wicd:
Before you connect to an access point, click on the properties button, and then the scripts button. There you will see four blank lines, one of the should be "Post-connection Script". On that line, just enter the location of your ssh script, in our case /scripts/ssh_tunnel.sh.
Now, in the event that you loose your connection its possible that the ssh_tunnel process will remain active even though the session will die.. in that event you may want to put a Post-disconnect Script in place that issues a "pkill ssh", which should take care of that issue.
That's it, you will have an encrypted tunnel at your disposal whenever you think you might need one, without having to touch the terminal again or remember the needed commands.