Configure OpenVPN on Raspberry Pi Kodi

This is a guide on how to get your VPN working on your Raspberry Pi using 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 use ActiVPN as my VPN provider, so I am using them as an example for this guide.


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 ActiVPN they can be download from this link: https://activpn.com/conf.zip


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 singapore.ovpn would become CAsingapore.ovpn


Step 4


Edit the file 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 ActiVPN-FR-2.ovpn from ActiVPN. It will look like this:

client
dev tun
proto udp
resolv-retry 5
nobind
persist-key
persist-tun
ns-cert-type server
comp-lzo
verb 3
auth-user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F7SoYW8GRPbtIZN2EdFrpwk/wdxGnGDXOh3pMvSzxSkEgN
uxvxH5WWgEuX7owNMYEeovSRkCwS+xBE8//TEwvnvMnpCiLFzyyxVSz/Gvy5DYZD
3S8TgGlAdyyHqmKDIojzbNizMzxkOJYtaPGRpoJaLFz8keM=
-----END CERTIFICATE-----



You can edit this file with

auth-user-pass /storage/.config/vpn-config/pass.txt


Download the pass.txt file from and put your credentials in.

What we are doing here is telling the ovpn file where to find your login details.


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 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)
click on: storage
click on: .config
click on: vpn-config
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)
click on: home
click on: pi
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:
So as the name of the vpn you edited so as we edited ActiVPN-FR-2.ovpn we would type
openvpn /storage/.config/vpn-config/ActiVPN-FR-2.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:
So as the name of the vpn you edited so as we edited ActiVPN-FR-2.ovpn we would type
pi@raspbmc:~$ sudo openvpn /home/pi/vpn-config/ActiVPN-FR-2.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: https://activpn.com/files/scripts/raspberry_pi/kodi/ (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.


Get this VPN - Configure OpenVPN on Raspberry Pi Kodi