Linux Security

How to Install a VPN on Any Raspberry Pi

Christian Cawley 10-05-2017

A virtual private network, or VPN, is a vital part of online privacy and security. In short, if you’re not already running one alongside your usual security tools, you should be. VPNs are available for Windows, Linux, and macOS, as well as Android and iOS.


But what if you’re using a Raspberry Pi?

raspberry pi 3

Most operating systems for the Pi are based on Linux; unfortunately, VPN providers don’t offer dedicated Pi software. If you need to set up a VPN for your Pi, perhaps to avoid some region-blocking in Kodi, then you’ll need to do some manual configuration.

We’re going to look at how to set this up. The following steps will work with all Debian-based distros, such as Raspbian Jessie 5 Ways New Raspbian Jessie Makes Raspberry Pi Even Easier to Use Following the release of Debian Jessie in July, the Raspberry Pi community has been blessed with a new release of the Raspbian variant, based on the "parent" distro. Read More , and the Kodi distros (like OpenElec and OSMC).

Why Use a VPN?

There are many good reasons to use a VPN, all of which eventually come down to user privacy. In short, a VPN client encrypts data from your PC or mobile and sends it via a VPN server. From this anonymous point, your online activity is hidden.


How might this be useful? Well, if you’re using your Raspberry Pi as a desktop computer Use Your Raspberry Pi Like a Desktop PC There are so many amazing things that you can do with a Raspberry Pi, from running your own space program to building a media centre. Although ostensibly intended as a compact computer that can be... Read More and you’re based in a region where online censorship is rife, a VPN can help circumnavigate such restrictions. The same technology can help even if you just want to download software for your Pi while living under an oppressive regime.

http error 451
Image Credit: M-SUR via Shutterstock

For a Kodi media center, a VPN might circumvent region-blocking, censorship, or anything else blocking your access to media.

For instance, if you wanted to access BBC iPlayer from the U.S. (and if you’re a traveling British citizen, there’s no reason why you shouldn’t), a VPN can help. By connecting to a VPN in the U.K., you’ll be able to stream your favorite TV show (Doctor Who, perhaps). You should be confident that it is legal to enjoy your media center What Are Kodi Boxes and Is It Legal to Own One? In this article, not only do we explain what Kodi boxes are, but also offer you a definitive answer on their legality. Read More in the way you have planned, however.


My guide, 10 Reasons Why You Should Be Using a VPN 11 Reasons Why You Need a VPN and What It Is Virtual private networks can protect your privacy. We explain what exactly they do and why you should use a VPN. Read More , should explain more. Meanwhile, if you want more of a background on the encryption, security, and how a VPN works, check our VPN primer What Is The Definition Of A Virtual Private Network Virtual private networks are more important now than ever before. But do you know what they are? Here's what you need to know. Read More .

As noted, there are also other ways to use a VPN. You might like to run a VPN on your desktop computer, for instance, or set up some universal defense by setting up a VPN account on your router.

Either way, you should be using one.

How to Choose a VPN

If you’re simply browsing the web and wish to do so in privacy, then a standard VPN (albeit one offering minimal logs) should be chosen.


However, if you wish to beat region blocking or use a streaming add-on in Kodi, then you need to find a VPN that will offers unlimited bandwidth for video streaming. It will also need to be peer-to-peer-friendly, as many add-ons use P2P networking for streaming content.

Just make sure you’re using a VPN service that is trustworthy 5 Ways Your VPN Is Not as Private as You Think It Is Your VPN is not as secure or private as you think it is. We explain why you and your browsing history might not be anonymous after all. Read More .

Requirements for a VPN on the Raspberry Pi

To use a VPN on a Raspberry Pi, you will need the following things:

raspberry pi ssh putty


OpenVPN is an open-source VPN application that enables you to use the configurations provided by VPN services using OpenSSL for encryption. In short, you can set up a VPN on a Raspberry Pi without a dedicated app.

You have two options for setting up a VPN. The first is to install OpenVPN within Raspbian (or your chosen Raspberry Pi OS). Alternatively, you can set up a VPN within your preferred Kodi image Install Kodi to Turn Your Raspberry Pi Into a Home Media Center If you have a Raspberry Pi, you can turn it into a cheap but effective home media center just by installing Kodi. Read More .

Set Up a VPN on Your Raspberry Pi

With various images available for the Pi, this can get a little fiddly.

Fortunately, as long as you’re using a Debian-based image, this solution will work. It doesn’t matter whether you’re using Kodi or not. This is a straightforward method for running a VPN on your Raspberry Pi regardless of operating system or disk image.

We’ve tried this out using the OSMC flavor of Kodi, which, like Raspbian, is based on Debian. However, it should also work on OpenElec.

openvpn installation terminal

Begin by connecting to your Raspberry Pi via SSH Setting Up Your Raspberry Pi For Headless Use With SSH The Raspberry Pi can accept SSH commands when connected to a local network (either by Ethernet or Wi-Fi), enabling you to easily set it up. The benefits of SSH go beyond upsetting the daily screening... Read More , using the correct credentials for your media center image, and installing openVPN:

sudo apt-get install openvpn

Once complete, issue the reboot command:

sudo reboot

When your Pi has restarted, you’ll need to download the openVPN files from your VPN provider. The overwhelming majority of services offer support for openVPN.

openvpn sftp

The most expedient way to do this is download the files to your PC, extract them (they’re typically ZIP files), and then send them to your Raspberry Pi via SFTP 5 Ways to Copy Data From a Raspberry Pi to a PC At some point you're going to want an easy way to get the data off the Pi's SD card and onto your PC's HDD. This can be tricky. Read More . Create a new folder for their destination, called openvpn-config. This should be within /home/.

Once these files are copied, use SSH to issue the run command:

sudo openvpn your_ovpn_configuration_file.ovpn

You’ll be prompted for your VPN username and password, so enter these.

openvpn prompt username password

Within moments, the VPN connection should be established, and you’ll be enjoying a fully private Raspberry Pi Kodi experience. You’re ready to go region-free!

Note that if you’re running Kodi on a different device or platform, you should be able to install a VPN via a dedicated add-on.

Disconnecting and Changing the VPN

Should you wish to disconnect the VPN, you’ll need to hit Ctrl + C to end the session. To connect to a different server, simply repeat the earlier command, but with a different configuration file. Each connection will require a username and password.

If you’re using the VPN with Kodi, you’ll need to leave it running. As a result, it might be useful to set up an SSH or VNC connection via an app on your mobile device Setup VNC on Raspberry Pi to Remotely Control It with Any PC or Phone You can have a full Raspberry Pi desktop interface with ever connecting a monitor, keyboard or mouse. Now that the latest version of Raspbian includes RealVNC server, it's easier than ever. Read More  and use this to monitor the VPN. Should the connection drop, for example, you’ll need access to re-enable it. If you’re using a Kodi remote app The 3 Best Free XBMC Remote Apps For iPhone & iPad One of the best things about XBMC is its compatibility with remote control applications, of which there are no shortage on the App Store. Today we’ll be taking a look at the best free remotes... Read More , it makes sense to have your remote access all in one place!

Do you need to use a VPN with your Raspberry Pi? Perhaps you already use one? Tell us how it worked out for you.

Related topics: Raspberry Pi, VPN.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. C6d3n
    September 27, 2018 at 11:38 pm

    will this work on a raspberry pi zero

  2. Hein
    May 12, 2017 at 9:25 am

    Why not use your Raspberry as a VPN server.
    By far the easiest setup is PiVPN

  3. Peklo
    May 11, 2017 at 7:17 pm

    As usual it is not as straight forward in the real life, especially when it comes to unlocking the BBC. Their engineers are not as daft, as we'd wish them to be and have blocked most VPN end points in the UK. Once they see a disproportionately high traffic from an IP, it gets blocked.

    • Christian Cawley
      May 12, 2017 at 7:56 am

      I wouldn't disagree with that, but the setting up of the VPN is straightforward. It's what you do with it after that can be a challenge.

      Unblocking the BBC can be difficult, even if you're using a UK-based VPN, for exactly the reasons you cite. It's essentially one-up-manship.

  4. Corpagro
    May 11, 2017 at 6:30 am

    I will try it. Thx