Install and Configure OpenVPN on OSMC/Kodi

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

Install OpenVPN.
root@KODI:/home/osmc# apt-get install openvpn

Reboot.
root@KODI:/home/osmc# reboot

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 osmc@192.168.1.100:/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
    line.
  • Press Esc, type :wq
Username
Password

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:
    • auth-user-pass
    • ca
  • 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!

Advertisements

38 thoughts on “Install and Configure OpenVPN on OSMC/Kodi

  1. 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.

  2. 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
    import xbmc
    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.

  3. Hi,
    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?
    Cheers

    • 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

      OpenVPN
      Set this to the OpenVPN binary.
      Default: /usr/bin/openvpn

      • 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

    • 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.

    • 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.

  4. 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.

  5. 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…

  6. 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.

  7. 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!

  8. 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….

  9. 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…

  10. Hey there,
    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?

    • Hi,
      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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s