How To Set Up Your VPN Client

20 February 2015

The following guide originally appeared on the TV Addons forum. Many thanks to the original author "invisable" for letting me reproduce it here.

This is a guide on how to get your VPN working on your Raspberry Pi using Brian Hornsby's OpenVPN for Kodi add-on. I have tested this and it works for both Raspbmc and OpenELEC (still to test on XBian). It also works on the OpenELEC versions of Kodi on the Hummingboard so it will probably work on the CuBox-I. This add-on does not work on Apple TV due to it not having a OpenVPN client installed also this only works on Gotham/Kodi and later builds of OpenELEC.

The add-on is a bit simpler then the previous method, which used advanced launcher, but still involves a little bit of work which includes modifying a few files. This guide assumes that you know the basics and you know how to move files and folders from your PC/Mac to your Raspberry Pi. I have tried to make this a simple as possible, thank to rayw1986 as he originally brought the method of editing the files to my attention, also thanks to Brian Hornsby the developer for writing the add-on.

I use Private Internet Access (PIA) as my VPN provider, so I am using them as an example for this guide. Please note: If you are also using using PIA you may need to generate a password for socks, pptp to use on this guide, this can be done by logging into PIA and clicking generate password from the client control panel.

Step 0 (Raspbmc only)

Raspbmc doesn't have a OpenVPN client installed by default so the first thing we need to do is download one so log in via putty

username: pi
password: raspberry

If you see the timezone setup message and do not want to set it all up, just hit ctrl+C on your keyboard to abort it, you should then see the UNIX bash prompt.

You need to be super user to setup OpenVPN so enter:

pi@raspbmc:~$ sudo bash

The prompt should change to indicate you are root. It's a good idea to update the software repositories first so enter:

root@raspbmc:/home/pi# apt-get update

Depending on your connection it may take a few minutes to complete. To install OpenVPN enter:

root@raspbmc:/home/pi# apt-get install openvpn

This will also take a few minutes, once finished you will be returned to the prompt, now you can exit putty and restart your raspberry pi.

Step 1

First thing you need to do is download your clients vpn configuration including the certificate files if needed. for PIA they can be download from this link: https://www.privateinternetaccess.com/openvpn/openvpn.zip. There are a couple of free OpenVPN services don't know how good they are but if you want to set up a free one you could try these: http://freevpn.me/accounts the certificate files are usually included in the .ovpn files

Step 2

Once your VPN configuration files have been downloaded extract it to a folder on your computer (I created a folder on the desktop and extracted them there).

Step 3

Open up the folder where you extracted all your configuration files to and remove all the spaces in the names of the locations you want to use, so for example. CA North York.ovpn would become CANorthYork.ovpn

Step 4

Open up notepad++ if you havent got this it is free to download from here http://notepad-plus-plus.org/download/ On the first line you need to type your username (nothing else). On the second line type your password (nothing else). Click file and save it as pass.txt (make sure it is a txt file)this should be saved into the same folder where you extracted your VPN configuration files.

Step 5 (OpenELEC)

Open up one of the OpenVPN configuration files you want to use for example this is USMidwest.ovpn from PIA. It will look like this:

client
dev tun
proto udp
remote us-midwest.privateinternetaccess.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
tls-client
remote-cert-tls server
auth-user-pass
comp-lzo
verb 1
reneg-sec 0
crl-verify crl.pem

You need to edit the lines beginning with ca ca.crt and auth-user-pass. Also we need to edit the last line "crl-verify crl.pem" so it looks like this:

client
dev tun
proto udp
remote us-midwest.privateinternetaccess.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca /storage/.config/vpn-config/ca.crt
tls-client
remote-cert-tls server
auth-user-pass /storage/.config/vpn-config/pass.txt
comp-lzo
verb 1
reneg-sec 0
crl-verify /storage/.config/vpn-config/crl.pem

What we are doing here is telling the ovpn file where to find your certificate and login details. (Sometimes the certificate is inserted into the OpenVPN file so you will not need to edit the line that starts with ca)

Step 5 (Raspbmc)

Open up one of the OpenVPN configuration files you want to use for example this is USMidwest.ovpn from PIA. It will look like this:

client
dev tun
proto udp
remote us-midwest.privateinternetaccess.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
tls-client
remote-cert-tls server
auth-user-pass
comp-lzo
verb 1
reneg-sec 0
crl-verify crl.pem

You need to edit the lines beginning with ca ca.crt and auth-user-pass. We also need to edit the path or delete the last line "crl-verify crl.pem" so it looks like this:

client
dev tun
proto udp
remote us-midwest.privateinternetaccess.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca /home/pi/vpn-config/ca.crt
tls-client
remote-cert-tls server
auth-user-pass /home/pi/vpn-config/pass.txt
comp-lzo
verb 1
reneg-sec 0
crl-verify /home/pi/vpn-config/crl.pem

What we are doing here is telling the ovpn file where to find your certificate and login details. (Sometimes the certificate is inserted into the OpenVPN file so you will not need to edit the line that starts with ca).

Step 6

Repeat the process of Step 5 to all the ovpn configuration files you want to use from within Kodi

Step 7

Once you have modified all the .ovpn/.conf files that you want to use it is time to move them onto your pi.(there are many ways to do this but the easiest way for those who really dont know is just to put the files on a usb stick (fat32) that way you can plug it into your pi).

On Kodi go into Settings->Appearance->File lists and make sure "show hidden files and directories" is checked. Next open the filemanager in Kodi, click on add source a window will pop up. Click "Root filesystem" it will open up lots of folders ignore this just press the OK box. It will now take you back, click on the box at the bottom where it says "Enter a name for this media Source" name it Root then click OK at the bottom

Step 8 (OpenELEC)

If you know what your doing the *.ovpn files you edited along with your pass.txt and the ca.crt need to be transferred onto you pi into /storage/.config/vpn-config if you dont understand this carry on reading this Step. On the Kodi file manager you should see the new source in window, which is called root, click on this on WINDOW A, on the left.

WINDOW A (LEFT SIDE)

This folder will be empty but if you look under the big letter A you can see it is listed /storage/.config/vpn-config.

WINDOW B (RIGHT SIDE) next put in your (fat32) usb stick into your pi and wait a couple of seconds for the pi to recognize it and you should see it pop up in WINDOW B on the left side of your TV screen go into the location on the usb stick where transferred all of your edited ovpn files, your pass.txt ad the ca.crt file. bring up context menu over each of the files and select copy it will now appear in window A it is important that you copy all the files across including pass.txt ca.crt

Step 8 (Raspbmc)

If you know what your doing the *.ovpn files you edited along with your pass.txt and the ca.crt need to be transferred onto you pi into /home/pi/vpn-config (you will need to create the folder vpn-config)if you don't understand this carry on reading this step. On the Kodi file manager you should see the new source in window which is called root click on this on WINDOW A on the left.

WINDOW A (LEFT SIDE)

Bring up context menu and create a folder, make sure that this folder is named vpn-config Now click on: vpn-config This folder will be empty but if you look under the big letter A you can see it is listed /home/pi/vpn-config

WINDOW B (RIGHT SIDE) next put in your (fat32) usb stick into your pi and wait a couple of seconds for the pi to recognize it and you should see it pop up in WINDOW B on the left side of your TV screen go into the location on the usb stick where transferred all of your edited ovpn files, your pass.txt ad the ca.crt file. bring up context menu over each of the files and select copy it will now appear in window A it is important that you copy all the files across including pass.txt ca.crt

Step 9 (OpenELEC)

Log into your Raspberry Pi using putty

username: root
password: openelec
We need to check your work so at the command prompt type:
openvpn /storage/.config/vpn-config/whatever_your_vpn_is_called.ovpn
So as the name of the vpn you edited so as we edited USMidwest.ovpn we would type
openvpn /storage/.config/vpn-config/USMidwest.ovpn
The VPN service should start, if it completed successfully you will get a message saying so and you will have to exit out of your ssh client

Step 9 (Raspbmc)

Log into your pi using putty

username: pi
password: raspberry
We need to check your work so at the command prompt type:
pi@raspbmc:~$ sudo openvpn /home/pi/vpn-config/whatever_your_vpn_is_called.ovpn
So as the name of the vpn you edited so as we edited USMidwest.ovpn we would type
pi@raspbmc:~$ sudo openvpn /home/pi/vpn-config/USMidwest.ovpn
The VPN service should start, if it completed successfully you will get a message saying so and you will have to exit out of your ssh client

Step 10

So if all is successful you now have a working VPN if you wanted to check that your connected to you vpn run the hub maintenance tool and there is a option to check you ip address and location. Anyway now we need to install the OpenVPN script it can be found here: http://brianhornsby.com/downloads/ (click on script.openvpn-?.?.?.zip)

Step 11

Once you have installed the script go to programs highlight the OpenVPN script and bring up the context menu and select addon-settings. We now need to tell the addon where the OpenVPN client is so it can run the script so on the first page click on the box where it says "openvpn" you will need to back up by selecting the .. or pressing the backspace key untill you can back up anymore. Select "Root file system" then select the folder "usr" select the folder "sbin" select "openvpn" and click ok in the box the path that should be writen should be /usr/sbin/openvpn. (Raspbmc ONLY) For Raspbmc you need to run the script using the sudo command so while in the addon setting move along to the second page called script and check the box that says "run openvpn using sudo" make sure the box underneath that says "password" in left unchecked.

Step 12

Now all that is left to do is import you ovpn files, in the addon-setting select import openvpn file and import your edited ovpn files, it will ask you to name them to what you want. once you have imported all the locations you want to use, run the addon and select your chosen location. to dissconnect open up the addon again and select disconnect at the bottom

Good luck and don't forget to keep a backup of all your edited files!!! The OpenELEC backup tool doesn't backup any of the content from the .config folder so I always manually take a copy of this folder that way its easy if anything happens to your system.