Let’s face it, Kodi is pretty popular right now, everyone is talking about it. One of the first things I did after I installed OSMC on my Raspberry Pi was to configure OpenVPN. There is a little bit of work involved so I figured I’d share what I did to get it up and running!
Login to OSMC via SSH using PuTTy or your client of choice.
Elevate to Super User.
osmc@KODI:~$ sudo su
Update the software repositories.
root@KODI:/home/osmc# apt-get update
root@KODI:/home/osmc# apt-get install openvpn
Create a folder to put your OpenVPN configuration files in.
osmc@KODI:~$ sudo su
root@KODI:/home/osmc# mkdir vpn-conf
Copy your .opvn file/files and your .crt file into /home/osmc/vpn-conf, there are a few ways to copy the files here, I personally like to use PSCP. This
example is using PSCP from a Windows computer.
C:\temp>pscp c:\temp\ca.crt firstname.lastname@example.org:/home/osmc/vpn-conf
Create a new file that will contain your login credentials for OpenVPN
root@KODI:/home/osmc# cd vpn-conf
root@KODI:/home/osmc/vpn-conf# vi login.conf
- Press Insert
- Type your Username on first line press enter and type your password on the next
- Press Esc, type :wq
Now edit the .opvn file/files of choice to make sure the login.conf and <ca_file_name>.crt file are referenced correctly.
root@KODI:/home/osmc/vpn-conf# vi <filename>.ovpn
- Find the following lines that begin with:
- If they exist – edit them accordingly, if they don’t exist you will need to add them.
auth-user-pass /home/osmc/vpn-conf/login.conf ca /home/osmc/vpn-conf/ca.crt
Let’s test out OpenVPN, the service should start and connect successfully after running this command.
root@KODI:/home/osmc/vpn-conf# openvpn /home/osmc/vpn-conf/<filename>.ovpn
Confirm VPN connectivity by using curl, this should retrieve your VPN’d IP address.
root@KODI:/home/osmc/vpn-conf# curl http://checkip.dyndns.org
If everything checks out and is working so far it’s time to install the OpenVPN Add-On for
Kodi and import a profile. Grab the latest OpenVPN Add-On for Kodi, the quickest way is to just grab it is to use wget right from OSMC, using your web browser right-click on the script.openvpn-x.x.x.zip and Copy the link address.
root@KODI:/home/osmc/vpn-conf# wget -c <paste_link_addr_here>
From Kodi on your TV, go to Settings -> Add-ons -> Install from zip file
- Select Install from zip file.
- Navigate to the ZIP file and select it.
- In the bottom right corner, Kodi notifies when the add-on is installed and enabled.
Now the OpenVPN Add-On for Kodi should be installed… go to Programs > Add-Ons
> OpenVPN from Kodi and import your .opvn files, once complete try to connect. It should work successfully since it’s literally just an interface to the actual OpenVPN service that we just installed and configured.
That’s it! …but if you’d like to take it one step further you can. I personally like to have a certain OpenVPN profile connect at startup of Kodi. It’s pretty simple to do this.
Browse to the userdata folder for Kodi and create an autoexec.py file.
root@KODI:/home/osmc# cd /home/osmc/.kodi/userdata
root@KODI:/home/osmc/.kodi/userdata# vi autoexec.py
- Type the following where <profile_name> is the profile
name of the profile you have created in the OpenVPN Add-On for Kodi.
import xbmc xbmc.executebuiltin('XBMC.RunScript(script.openvpn,<profile_name>)')
Now every time you power on your Kodi box, OpenVPN will launch and the VPN
profile of choice will connect automatically. Cheers and happy streaming!
Hello, what are the username and password? Is that from OpenVPN Access Server Client license subscription? Thx!
The username and password are the credentials that are provided by your VPN provider. Typically you can log in and retrieve these from your VPN provider’s website.
Thanks for your prompt reply.
Any good VPN provider you can recommend?
Just curious, any good and reliable Free VPN provider for OSMC/Kodi?
There may be some, I’ve never personally tried a free one. My concern would be around the bandwidth and the ability to stream video with a free provider. My guess is it would be hard to find a free provider that would be lag free upon streaming, if there was such a provider everyone would be jumping on board. There are quite a few quality providers, many people I know recommend PIA, Private Internet Access (https://www.privateinternetaccess.com/). There are certainly many more providers out there, I use TigerVPN and it’s ok for the most part, sometimes though it does get a bit choppy when streaming.
i know i am late, but how do you login and get the username and password, i tried everything and never got anything
Thanks again for the prompt reply. Will try ut your solution on my Pi 3.
Really enjoy your blog!
Thanks for the kind words and good luck, if you have any questions just let us know.
Great write up, thank you! For the auto start, I keep getting:
# python autoexec.py
Traceback (most recent call last):
File “autoexec.py”, line 1, in
ImportError: No module named xbmc
Any idea what can be causing this? I’m using OSMC build and everything works well manually.
The only thing I can think of is it can’t be run outside of xbmc. If you are calling it from outside of xbmc you will see an import error.
It’s being called within XBMC. I did figure out the python script works on start up, just doesnt work when manually calling it.
Great write up. I have an issue though. The addon doesn’t seem to find openvpn program. After successfully importing and naming my configuration when I click on it I get an error about openvpn not being found. When I run openvpn by hand it connects. Where should the binary be?
According to the documentation there should be an option in the OpenVPN add-on to set the binary location. By default it looks in /usr/bin/openvpn
Set this to the OpenVPN binary.
Hi ! I have the same problem but I don’t understand where it should look if it isn’t in /usr/bin/openvpn
Ok it’s in /usr/sbin as Osay said sorry ^^, but still got the message “unable to connect to openvpn management interface”.
Anyway if I can’t get it working this way I’ll be fine with the launching openvpn at startup, so thx for your nice tuto.
I meant at linux startup with a rc.local script. Working fine btw. sorry for spam
Never mind. I had to make the addon point to /usr/bin/openvpn instead of /usr/sbin/openvpn.
Happy to hear you got it working!
I have literally spent the entire day looking for this precise tutorial to use with IPVanish. Nobody had anything even remotely close to this step by step walkthru. Thank you so much!
Update: While I can get the SSH commands to work, I wasn’t ever able to get the app working. Says it’s Connecting to.. which is 99% further than I ever got before but when I check the IP using the command above.. it’s my usual IP. But the shell commands work to initiate the connection? So I am not sure why the app doesn’t work given I was able to establish a VPN. Regardless, fantastic tutorial. It’s really not that easy using OSMC and even their forums don’t have anything this useful.
That’s strange, do I understand this correctly? When you run the commands from SSH it works but from the OpenVPN add-on it won’t connect? The only thing I can really think of is maybe a file permission issue? That is a weird scenario.
You’re welcome, happy to hear it was useful for you!
The fix was … inside of OpenVPN one of the settings is to run as sudo but not require a password! Once I selected that.. it mimicked the SSH perfectly and does indeed work!
Before I found this guide, I emailed IPVanish to ask how to configure it with OSMC and a Raspberry Pi. They told me it wasn’t possible.
Well, I have it running! Fools.
Am I OK to send them a link to this guide? Maybe they can use it.
Haha glad to hear it worked for you, that interesting they’d say it was not possible… I guess we proved them otherwise 🙂 go ahead and share the knowledge.
Thanks for this great tutorial. I have completed all steps,but when I attempt to Import my opvn files nothing is show (even though the files are in the vpn-conf directory and have I successfully completed a VPN connection manually. I see one network location when I attempt to import the opvn files, but not vpn-conf. I have checked the “Run as Sudo” option and left the “require password” option blank. So I’m not sure what I’m missing. Any assistance will be greatly appreciated.
The only thing I can think of is maybe the read/execute permission on the opvn files, try “chmod 555 “
Try adding the vpn-conf as a source. Then it will be able to find
I keep getting tis error. any ideas?
Options error: –tls-auth fails with ‘ta.key’: No such file or directory
Options error: Please correct these errors.
perhaps your ovpn file calls for a ta.key but you didn’t actually include it in your vpn-config folder? my ovpn files didn’t require a ta.key file because the authentication wasn’t as thorough as some i’ve seen and frankly i was happier for an easier setup. try removing the line in your ovpn file calling the ta.key and see if that works. i had options for my VPN that had a ta.key and some that didn’t and i just used the ones that didn’t…
great guide, unfortunately when i try to move files into the folder vpn-conf it densies me the permission, either with pscp or filezilla and cyberduck
Sounds like a permissions issue, check the permissions on the folder and make sure you are using elevated privileges.
Thanks for publishing this awesome article. I’m reading your blog since a long
time already but I never compelled to leave a comment.
I registered your blog in my rss feed and shared it on my Twitter.
Thanks again for this great post!
Thanks for the kind message, we are thankful that we can help others like yourself.
HI, thanks for this works great up to where i have to configure OpenVPN on the Kodi via TV. When i’ve installed and opened the addon it asks me for a configuration file, and only lets me look in two locations on storage. I’ve added the .ovpn file but it still asks me for a config file. Any thoughts ? Thanks, Stu
the configuration file is the ovpn file (that’s been altered to reflect an accurate path to it and the credentials file). it should work as long as you have the correct path(s) in it….
I have the OpenVPN running perfectly on kodi….but for the autoexec.py part, I ran the code and nothing happens at startup. do i have to put the openvpn path in the 2 lines of code to get it to work? maybe its something else…
Thanks for your smooth configuration guid. however, I have a minor issue. I follow up the steps and everything works fine, until here: “Now the OpenVPN Add-On for Kodi should be installed… go to Programs > Add-Ons> OpenVPN from Kodi and import your .opvn files”. when I opened the OpenVPN Add-On there is no .opvn files. I looked up inside the existing folders but I was not able to find .opvn files which I was configured. Do you know what went wrong or did I miss something?
I also had this issue, you need to go into file browser and click on the magnifying glass then navigate to the vpn-conf folder that holds your ovpn files (in the home directory). Hope that helps.
I’m not sure it worked for me though, I ran through all the steps but im not sure the add on i got is the right one. Going to try another one from the Zomboided repository and if that doesn’t work, I’m giving up on osmc and going over to libreelec as ive seen a guide to get openvpn working on that.
Hope you have some success!
Thanks for this great tutorial. I wonder if there is a way to add a kill switch into openvpn on kodi and how?
After using your instructions to Install and Configure OpenVPN on OSMC/Kodi (ATV1) couldn’t get connected to PureVPN service andmy Mac Terminal shows some errors that I don’t understand:
osmc@osmc:/$ cd /home/osmc/vpn-conf
osmc@osmc:~/vpn-conf$ openvpn London1UK.ovpn
Mon Oct 2 18:57:25 2017 OpenVPN 2.3.4 i586-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [MH] [IPv6] built on Jun 26 2017
Mon Oct 2 18:57:25 2017 library versions: OpenSSL 1.0.1t 3 May 2016, LZO 2.08
Mon Oct 2 18:57:25 2017 WARNING: file ‘/home/osmc/vpn-conf/login.conf’ is group or others accessible
Mon Oct 2 18:57:25 2017 WARNING: No server certificate verification method has been enabled. See http://openvpn.net/howto.html#mitm for more info.
Mon Oct 2 18:57:25 2017 WARNING: file ‘/home/osmc/vpn-conf/Wdc.key’ is group or others accessible
Mon Oct 2 18:57:25 2017 Control Channel Authentication: using ‘/home/osmc/vpn-conf/Wdc.key’ as a OpenVPN static key file
Mon Oct 2 18:57:25 2017 UDPv4 link local (bound): [undef]
Mon Oct 2 18:57:25 2017 UDPv4 link remote: [AF_INET]22.214.171.124:53
Mon Oct 2 18:57:28 2017 [PureVPN] Peer Connection Initiated with [AF_INET]126.96.36.199:53
Mon Oct 2 18:57:31 2017 ERROR: Cannot ioctl TUNSETIFF tun: Operation not permitted (errno=1)
Mon Oct 2 18:57:31 2017 Exiting due to fatal error
Thanks in advance for your help
Hi, thanks for the tuto, it worked fine for me.
However, I wish to automatically reconnect to VPN in case of network loss. Do you know a script able to do that? (in a similar way than connection at startup, as you suggested)
Have you ever considered creating an e-book or guest authoring on other sites? I have a blog based upon on the same ideas you discuss and would really like to have you share some stories/information. I know my readers would appreciate your work. If you are even remotely interested, feel free to send me an e-mail.