Goal: I want to be able to securely use the internet via my home PC while my notebook is connected to an open hotspot/access point.
I do know that I can use a SSH tunnel/SOCKS proxy, but I don't want to fiddle around with applications (making them use it, if even possible). I guess what I need is an OpenVPN setup, so I'm looking for a detailed guide on how to:
- Install and setup the OpenVPN server
- Setup the OpenVPN client (NetworkManager)
Ubuntu versions this should work on are 10.10 and 11.04.
I have the exact question a few months ago, but additionally, I wanted to have an IPv6 connection if possible. You might be interested in my questions on Serverfault:
I had only one NIC ("network interface") on my server for use. In my setup, NetworkManager was not sufficient because I need to run a custom script to support IPv6. For simplicity however, I will use NetworkManager here and omit the IPv6 support.
First, just make a decision on the authentication method. I'll be using the safer certificate method which works like SSL: during the handshake a common secret is chosen which will be used for the session. The other methods are a shared key; a username and password.
Server
1. Prepare
First, install the openvpn server. This is as easy as
sudo apt-get install openvpn
. The difficult part is configuring it. The configuration is present in/etc/openvpn
.2. Configure authentication
The server needs certificates for identifying itself and its clients. These certificate are retrieved from a CA (Common Authority). The creation of the certificates and related private keys can be done on any machine, it does not have to be done on the server. If you're really paranoid, you should do it on a machine which is not connected to a network, and use a memory stick for transferring the certificates.
Create a CA and certificates for the server
This step has to be done once unless your CA's private key got compromised. In that case, valid certificates can be created which will be accepted by the server, resulting in a security breach.
The official documentation suggests to do the administration in
/etc/openvpn
. I am not a big fan of running everything as root, so I will put it in a different directory.Create the administration directory and copy the files in it by running:
vars
as needed, for example settingKEY_SIZE=2048
because you are paranoid.Load the variables and create the key directory by running:
If you get an error that
No ... openssl.cnf file could be found Further invocations will fail
, runln -s openssl-1.0.0.cnf openssl.cnf
, then. vars
again.If this is your first time using this CA, prepare the keys environment. Do not run this command if you want to maintain your previously created CA. Doing so will require you to deploy a new
ca.crt
../build-ca
. You can fill any details in you want, but note that this information will be visible in log files when the clients connects to the server. This will create the filesca.key
andca.crt
in the subfolderkeys
. Keep theca.key
file secret in all circumstances. Failure to do so will allow anyone with the key to connect to your server../revoke-full server
. Otherwise you get a database error.Create the certificate for the server by running:
When being asked for a password, leave it empty unless you are willing to enter the password each time the server starts (not recommended). Confirm on signing the certificate and committing it. Two new files will appear in the directory
keys
:server.key
andserver.crt
.DH and use prepare for tls-auth
Generate Diffie-Hellman parameters using:
Per hardening tips, use
tls-auth
. For that, generate the shared-secret key using:The resulting file (
ta.key
) must be distributed to clients as well, but you should not put it in public.Create certificates for clients
For each client, these steps should be repeated:
Enter the directory in which you created your CA and server certificate:
If you've skipped the CA creation step because you've already one, you need to load the variables first:
./revoke-full you
. Otherwise you get a database error.Create the clients certificate
you.key
and its corresponding certificateyou.crt
:The
CommonName
should be unique. Leave the password empty if you're using KDE as it's not supported yet as of 10.10. As with the server certificate generation, confirm signing the cert and committing the changes.3. Setup the OpenVPN service
By default, OpenVPN runs as root when accepting connections. Not a good idea if the service is reachable from the evil Internet.
Create the a dedicated user for OpenVPN, say
openvpn
:Copy the files
server.key
,server.crt
,ca.crt
anddh1024.pem
(ordh2048.pem
if you've changed key size) from the keys directory into/etc/openvpn
. A permission of 400 (read-only for owner) is fine.Copy the file
ta.key
as well:Create the file
/etc/openvpn/server.conf
and put the next lines into it:Set the appropriate permissions on it, it does not need to be secret, but I prefer not leaking configuration details so:
4. Finishing the server
If you've created the certificates on the server, it's a good idea to encrypt it or move it off the server. In any case, do not lose the
ca.key
andserver.key
. In the first case others will be able to connect to your server. In the latter, a MITM is possible.Client
Besides the server IP address, the server administrator should hand over the following files:
ca.crt
: for verifying the certificatesserver.crt
: for verifying the server and communicating with itta.key
: for hardening the securityyou.crt
: to identify yourself with the serveryou.key
: it's like your password, file permissions should be 400 (read-only for owner)1. Installation
Install OpenVPN and the NetworkManager plugin (suitable for KDE and Gnome):
network-manager-openvpn
is in the universe repository.2. Configuration
In the control panel, use the following details:
ca.crt
you.crt
you.key
At Advanced:
Specify the Key File path to
ta.key
and set "Key Direction" to1
.If you cannot get NetworkManager working or do not want to use it, put the files (
ca.crt
, ...) in/etc/openvpn
and create the file/etc/openvpn/client.conf
file:If you do not want to enable this VPN on boot time, edit
/etc/default/openvpn
and uncomment the next line by removing the#
:To start this connection, run:
client
should be renamed if your configuration file is not namedclient.conf
. Example: if you've named your configuration filesafe.conf
, you need to runsudo /etc/init.d/openvpn start safe
.To stop OpenVPN, you have to run:
You don't actually need to fiddle with any applications. This works "just like VPN."
First install the
tsocks
package (temporary socks):Then edit
/etc/tsocks.conf
and enterNow, open a terminal and type (this connects you):
Run (via another terminal or ALT-F2):
Now, Firefox transmits all communication through to the SOCKS server on your computer that SSH created. This further gets tunneled to your home machine, where it goes to the web. All you need on your home machine is an SSH server. After the first time, just repeat steps 3 and 4.
It works like a charm! Alas, chromium doesn't like tsocks, but hey, Firefox works.
The SSH tunnel solution is easier than you think. A program like gSTM will start/stop the tunnels for you with a GUI. Then just open Network Proxy and change it from Direct internet connection to Manual proxy configuration, hit "Apply system-wide" and all your apps should send their data down the tunnel - no need to fiddle with each one individually.