I wanted a free, secure, open source proxy for Ubuntu. I wanted minimal setup and I wanted it to just work.
And it does.
For this little tip, I assume you have an SSH server set up and SSH key-based authentication (though this may work with password authentication).
Add these commands to your .profile (replacing user and host). Create the file if it doesn’t exist.
$SHELL $HOME/.proxy &
Create the file .proxy in your home folder with these contents.
sleep 10s
ssh -fNqq -o "ExitOnForwardFailure yes" -D 9999 user@host
Run the following command in your terminal.
ssh -fNqq -o "ExitOnForwardFailure yes" -D 9999 user@host
And then go to System > Preferences > Network Proxy
Select Manual Proxy Configuration
Socks Host: localhost
Port: 9999
Now all your traffic will be encrypted using SSH! You can leave now or read on to understand why I did it this way.
Nitpicking: If another app or user is using port 9999, this will fail.
Rationale
.profile executes the .proxy file in the background using another shell instance. The shell already in memory is used.
Because the shell is executed in the background, it does not freeze the login process.
Then sleep is executed. This is necessary or the password dialog won’t appear.
At which point we execute ssh silently (qq), in the background (f), without a command (N) and with a proxy server at port 9999 (-D 9999). The option ExitOnForwardFailure is set to ‘yes’ to end the process if port 9999 is already being used.