Simple OpenVPN Raspberry Pi Installer
This is a set of shell scripts that serve to easily turn your Raspberry Pi (TM) into a VPN server using the free, open-source OpenVPN software. The master branch of this script installs and configures OpenVPN on Raspbian Jessie and has been tested on Ubuntu 14.04 running from an Amazon AWS image. The scripts do try to detect different distributions and make adjustments accordingly. They should work on the majority of Ubuntu and Debian based distributions including those using UFW by default instead of raw iptables.
This scripts primary mission in life is to allow a user to have a home VPN for as cost effective as possible and without being a technical wizard. Hence the design of pivpn to work on a Raspberry Pi ($35) and then one command installer. Followed by easy management of the VPN thereafter with the ‘pivpn’ command
Prerequisites
To follow this guide and use the script to setup OpenVPN, you will need to have a Raspberry Pi Model B or later with an ethernet port, an SD or microSD card (depending on the model) with Raspbian installed, a power adapter appropriate to the power needs of your model, and an ethernet cable or wifi adapter to connect your Pi to your router or gateway. It is recommended that you use a fresh image of Raspbian Jessie Lite from https://raspberrypi.org/downloads, but if you don’t, be sure to make a backup image of your existing installation before proceeding. You should also setup your Pi with a static IP address (see either source 1 or 2 at the bottom of this Readme) but it is not required as the script can do this for you. You will need to have your router forward UDP port 1194 (or whatever custom port you may have chose in the installer) (varies by model & manufacturer; consult your router manufacturer’s documentation to do this). Enabling SSH on your Pi is also highly recommended, so that you can run a very compact headless server without a monitor or keyboard and be able to access it even more conveniently
Installation
curl -L https://install.pivpn.io | bash
The script will first update your APT repositories, upgrade packages, and install OpenVPN, which will take some time. It will ask which encryption method you wish the guts of your server to use, 1024-bit, 2048-bit, or 4096-bit. If you’re unsure or don’t have a convincing reason one way or the other I’d use 2048 today. From the OpenVPN site:
For asymmetric keys, general wisdom is that 1024-bit keys are no longer sufficient to protect against well-equipped adversaries. Use of 2048-bit is a good minimum. It is wise to ensure all keys across your active PKI (including the CA root keypair) are using at least 2048-bit keys.
Up to 4096-bit is accepted by nearly all RSA systems (including OpenVPN,) but use of keys this large will dramatically increase generation time, TLS handshake delays, and CPU usage for TLS operations; the benefit beyond 2048-bit keys is small enough not to be of great use at the current time. It is often a larger benefit to consider lower validity times than more bits past 2048, but that is for you to decide.
After this, the script will go back to the command line as it builds the server’s own certificate authority. The script will ask you if you’d like to change the certificate fields, the default port, client’s DNS server, etc. If you know you want to change these things, feel free, and the script will put all the information where it needs to go in the various config files. If you aren’t sure, it has been designed that you can simply hit ‘Enter’ through all the questions and have a working configuration at the end.
Finally, the script will take some time to build the server’s Diffie-Hellman key exchange. If you chose 1024-bit encryption, this will just take a few minutes, but if you chose 2048-bit, it will take much longer (anywhere from 40 minutes to several hours on a Model B+). The script will also make some changes to your system to allow it to forward internet traffic and allow VPN connections through the Pi’s firewall. When the script informs you that it has finished configuring OpenVPN, it will ask if you want to reboot.
I have it where you do not need to reboot when done but it also can’t hurt.
Managing the PiVPN
After the installation is complete you can use the command ‘pivpn’ to manage the server.
“pivpn add” You will be prompted to enter a name for your client. Pick anything you like and hit ‘enter’. You will be asked to enter a pass phrase for the client key; make sure it’s one you’ll remember. The script will assemble the client .ovpn file and place it in the directory ‘ovpns’ within your home directory.
If you need to create a client certificate that is not password protected (IE for use on a router), then you can use the ‘pivpn add nopass’ option to generate that.
“pivpn revoke” Asks you for the name of the client to revoke. Once you revoke a client, it will no longer allow you to use the given client certificate (ovpn config) to connect. This is useful for many reasons but some ex: You have a profile on a mobile phone and it was lost or stolen. Revoke its cert and generate a new one for your new phone. Or even if you suspect that a cert may have been compromised in any way, just revoke it and generate a new one.
“pivpn list” If you add more than a few clients, this gives you a nice list of thier names and whether their certificate is still valid or has been revoked. Great way to keep track of what you did with ‘pivpn add’ and ‘pivpn revoke’.
You can run just ‘pivpn’ to see all the options.
::: Control all PiVPN specific functions!
:::
::: Usage: pivpn <command> [option]
:::
::: Options:
::: -a, add [nopass] Create a client ovpn profile, optional nopass
::: -c, clients List any connected clients to the server
::: -d, debug Start a debugging session if having trouble
::: -l, list List all valid and revoked certificates
::: -r, revoke Revoke a client ovpn profile
::: -h, help Show this help dialog
::: -u, uninstall Uninstall PiVPN from your system!
Docs
Download
This is a set of shell scripts that serve to easily turn your Raspberry Pi (TM) into a VPN server using the free, open-source OpenVPN software. The master branch of this script installs and configures OpenVPN on Raspbian Jessie and has been tested on Ubuntu 14.04 running from an Amazon AWS image. The scripts do try to detect different distributions and make adjustments accordingly. They should work on the majority of Ubuntu and Debian based distributions including those using UFW by default instead of raw iptables.
This scripts primary mission in life is to allow a user to have a home VPN for as cost effective as possible and without being a technical wizard. Hence the design of pivpn to work on a Raspberry Pi ($35) and then one command installer. Followed by easy management of the VPN thereafter with the ‘pivpn’ command
Prerequisites
To follow this guide and use the script to setup OpenVPN, you will need to have a Raspberry Pi Model B or later with an ethernet port, an SD or microSD card (depending on the model) with Raspbian installed, a power adapter appropriate to the power needs of your model, and an ethernet cable or wifi adapter to connect your Pi to your router or gateway. It is recommended that you use a fresh image of Raspbian Jessie Lite from https://raspberrypi.org/downloads, but if you don’t, be sure to make a backup image of your existing installation before proceeding. You should also setup your Pi with a static IP address (see either source 1 or 2 at the bottom of this Readme) but it is not required as the script can do this for you. You will need to have your router forward UDP port 1194 (or whatever custom port you may have chose in the installer) (varies by model & manufacturer; consult your router manufacturer’s documentation to do this). Enabling SSH on your Pi is also highly recommended, so that you can run a very compact headless server without a monitor or keyboard and be able to access it even more conveniently
Installation
curl -L https://install.pivpn.io | bash
The script will first update your APT repositories, upgrade packages, and install OpenVPN, which will take some time. It will ask which encryption method you wish the guts of your server to use, 1024-bit, 2048-bit, or 4096-bit. If you’re unsure or don’t have a convincing reason one way or the other I’d use 2048 today. From the OpenVPN site:
For asymmetric keys, general wisdom is that 1024-bit keys are no longer sufficient to protect against well-equipped adversaries. Use of 2048-bit is a good minimum. It is wise to ensure all keys across your active PKI (including the CA root keypair) are using at least 2048-bit keys.
Up to 4096-bit is accepted by nearly all RSA systems (including OpenVPN,) but use of keys this large will dramatically increase generation time, TLS handshake delays, and CPU usage for TLS operations; the benefit beyond 2048-bit keys is small enough not to be of great use at the current time. It is often a larger benefit to consider lower validity times than more bits past 2048, but that is for you to decide.
After this, the script will go back to the command line as it builds the server’s own certificate authority. The script will ask you if you’d like to change the certificate fields, the default port, client’s DNS server, etc. If you know you want to change these things, feel free, and the script will put all the information where it needs to go in the various config files. If you aren’t sure, it has been designed that you can simply hit ‘Enter’ through all the questions and have a working configuration at the end.
Finally, the script will take some time to build the server’s Diffie-Hellman key exchange. If you chose 1024-bit encryption, this will just take a few minutes, but if you chose 2048-bit, it will take much longer (anywhere from 40 minutes to several hours on a Model B+). The script will also make some changes to your system to allow it to forward internet traffic and allow VPN connections through the Pi’s firewall. When the script informs you that it has finished configuring OpenVPN, it will ask if you want to reboot.
I have it where you do not need to reboot when done but it also can’t hurt.
Managing the PiVPN
After the installation is complete you can use the command ‘pivpn’ to manage the server.
“pivpn add” You will be prompted to enter a name for your client. Pick anything you like and hit ‘enter’. You will be asked to enter a pass phrase for the client key; make sure it’s one you’ll remember. The script will assemble the client .ovpn file and place it in the directory ‘ovpns’ within your home directory.
If you need to create a client certificate that is not password protected (IE for use on a router), then you can use the ‘pivpn add nopass’ option to generate that.
“pivpn revoke” Asks you for the name of the client to revoke. Once you revoke a client, it will no longer allow you to use the given client certificate (ovpn config) to connect. This is useful for many reasons but some ex: You have a profile on a mobile phone and it was lost or stolen. Revoke its cert and generate a new one for your new phone. Or even if you suspect that a cert may have been compromised in any way, just revoke it and generate a new one.
“pivpn list” If you add more than a few clients, this gives you a nice list of thier names and whether their certificate is still valid or has been revoked. Great way to keep track of what you did with ‘pivpn add’ and ‘pivpn revoke’.
You can run just ‘pivpn’ to see all the options.
::: Control all PiVPN specific functions!
:::
::: Usage: pivpn <command> [option]
:::
::: Options:
::: -a, add [nopass] Create a client ovpn profile, optional nopass
::: -c, clients List any connected clients to the server
::: -d, debug Start a debugging session if having trouble
::: -l, list List all valid and revoked certificates
::: -r, revoke Revoke a client ovpn profile
::: -h, help Show this help dialog
::: -u, uninstall Uninstall PiVPN from your system!
Docs
Download