Want to access the Internet safely and securely from your smartphone or laptop when connected to an untrusted network such as the WiFi of a hotel or coffee shop? A Virtual Private Network (VPN) allows you to traverse untrusted networks privately and securely as if you were on a private network. The traffic emerges from the VPN server and continues its journey to the destination.
When combined with HTTPS connections, this setup allows you to secure your wireless logins and transactions. You can circumvent geographical restrictions and censorship, and shield your location and any unencrypted HTTP traffic from the untrusted network.
OpenVPN is a full-featured open source Secure Socket Layer (SSL) VPN solution that accommodates a wide range of configurations. In this tutorial, we’ll set up an OpenVPN server on a Droplet and then configure access to it from Windows, OS X, iOS and Android. This tutorial will keep the installation and configuration steps as simple as possible for these setups.
Note: If you plan to set up an OpenVPN server on a DigitalOcean Droplet, be aware that we, like many hosting providers, charge for bandwidth overages. For this reason, please be mindful of how much traffic your server is handling.
See this page for more info.
To complete this tutorial, you will need access to an Ubuntu 16.04 server.
You will need to configure a non-root user with sudo
privileges before you start this guide. You can follow our Ubuntu 16.04 initial server setup guide to set up a user with appropriate permissions. The linked tutorial will also set up a firewall, which we will assume is in place during this guide.
When you are ready to begin, log into your Ubuntu server as your sudo
user and continue below.
To start off, we will install OpenVPN onto our server. OpenVPN is available in Ubuntu’s default repositories, so we can use apt
for the installation. We will also be installing the easy-rsa
package, which will help us set up an internal CA (certificate authority) for use with our VPN.
To update your server’s package index and install the necessary packages type:
The needed software is now on the server, ready to be configured.
OpenVPN is an TLS/SSL VPN. This means that it utilizes certificates in order to encrypt traffic between the server and clients. In order to issue trusted certificates, we will need to set up our own simple certificate authority (CA).
To begin, we can copy the easy-rsa
template directory into our home directory with the make-cadir
command:
Move into the newly created directory to begin configuring the CA:
To configure the values our CA will use, we need to edit the vars
file within the directory. Open that file now in your text editor:
Inside, you will find some variables that can be adjusted to determine how your certificates will be created. We only need to worry about a few of these.
Towards the bottom of the file, find the settings that set field defaults for new certificates. It should look something like this:
. . .
export KEY_COUNTRY="US"
export KEY_PROVINCE="CA"
export KEY_CITY="SanFrancisco"
export KEY_ORG="Fort-Funston"
export KEY_EMAIL="me@myhost.mydomain"
export KEY_OU="MyOrganizationalUnit"
. . .
Edit the values in red to whatever you’d prefer, but do not leave them blank:
. . .
export KEY_COUNTRY="US"
export KEY_PROVINCE="NY"
export KEY_CITY="New York City"
export KEY_ORG="DigitalOcean"
export KEY_EMAIL="admin@example.com"
export KEY_OU="Community"
. . .
While we are here, we will also edit the KEY_NAME
value just below this section, which populates the subject field. To keep this simple, we’ll call it server
in this guide:
export KEY_NAME="server"
When you are finished, save and close the file.
Now, we can use the variables we set and the easy-rsa
utilities to build our certificate authority.
Ensure you are in your CA directory, and then source the vars
file you just edited:
You should see the following if it was sourced correctly:
OutputNOTE: If you run ./clean-all, I will be doing a rm -rf on /home/sammy/openvpn-ca/keys
Make sure we’re operating in a clean environment by typing:
Now, we can build our root CA by typing:
This will initiate the process of creating the root certificate authority key and certificate. Since we filled out the vars
file, all of the values should be populated automatically. Just press ENTER through the prompts to confirm the selections:
OutputGenerating a 2048 bit RSA private key
..........................................................................................+++
...............................+++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [US]:
State or Province Name (full name) [NY]:
Locality Name (eg, city) [New York City]:
Organization Name (eg, company) [DigitalOcean]:
Organizational Unit Name (eg, section) [Community]:
Common Name (eg, your name or your server's hostname) [DigitalOcean CA]:
Name [server]:
Email Address [admin@email.com]:
We now have a CA that can be used to create the rest of the files we need.
Next, we will generate our server certificate and key pair, as well as some additional files used during the encryption process.
Start by generating the OpenVPN server certificate and key pair. We can do this by typing:
Note: If you choose a name other than server
here, you will have to adjust some of the instructions below. For instance, when copying the generated files to the /etc/openvpn
directroy, you will have to substitute the correct names. You will also have to modify the /etc/openvpn/server.conf
file later to point to the correct .crt
and .key
files.
Once again, the prompts will have default values based on the argument we just passed in (server
) and the contents of our vars
file we sourced.
Feel free to accept the default values by pressing ENTER. Do not enter a challenge password for this setup. Towards the end, you will have to enter y to two questions to sign and commit the certificate:
Output. . .
Certificate is to be certified until May 1 17:51:16 2026 GMT (3650 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
Next, we’ll generate a few other items. We can generate a strong Diffie-Hellman keys to use during key exchange by typing:
This might take a few minutes to complete.
Afterwards, we can generate an HMAC signature to strengthen the server’s TLS integrity verification capabilities:
Next, we can generate a client certificate and key pair. Although this can be done on the client machine and then signed by the server/CA for security purposes, for this guide we will generate the signed key on the server for the sake of simplicity.
We will generate a single client key/certificate for this guide, but if you have more than one client, you can repeat this process as many times as you’d like. Pass in a unique value to the script for each client.
Because you may come back to this step at a later time, we’ll re-source the vars
file. We will use client1
as the value for our first certificate/key pair for this guide.
To produce credentials without a password, to aid in automated connections, use the build-key
command like this:
If instead, you wish to create a password-protected set of credentials, use the build-key-pass
command:
Again, the defaults should be populated, so you can just hit ENTER to continue. Leave the challenge password blank and make sure to enter y for the prompts that ask whether to sign and commit the certificate.
Next, we can begin configuring the OpenVPN service using the credentials and files we’ve generated.
To begin, we need to copy the files we need to the /etc/openvpn
configuration directory.
We can start with all of the files that we just generated. These were placed within the ~/openvpn-ca/keys
directory as they were created. We need to move our CA cert, our server cert and key, the HMAC signature, and the Diffie-Hellman file:
Next, we need to copy and unzip a sample OpenVPN configuration file into configuration directory so that we can use it as a basis for our setup:
Now that our files are in place, we can modify the server configuration file:
First, find the HMAC section by looking for the tls-auth
directive. Remove the “;” to uncomment the tls-auth
line:
tls-auth ta.key 0 # This file is secret
Next, find the section on cryptographic ciphers by looking for the commented out cipher
lines. The AES-128-CBC
cipher offers a good level of encryption and is well supported. Remove the “;” to uncomment the cipher AES-128-CBC
line:
cipher AES-128-CBC
Below this, add an auth
line to select the HMAC message digest algorithm. For this, SHA256
is a good choice:
auth SHA256
Finally, find the user
and group
settings and remove the “;” at the beginning of to uncomment those lines:
user nobody
group nogroup
The settings above will create the VPN connection between the two machines, but will not force any connections to use the tunnel. If you wish to use the VPN to route all of your traffic, you will likely want to push the DNS settings to the client computers.
You can do this, uncomment a few directives that will configure client machines to redirect all web traffic through the VPN. Find the redirect-gateway
section and remove the semicolon “;” from the beginning of the redirect-gateway
line to uncomment it:
push "redirect-gateway def1 bypass-dhcp"
Just below this, find the dhcp-option
section. Again, remove the “;” from in front of both of the lines to uncomment them:
push "dhcp-option DNS 208.67.222.222"
push "dhcp-option DNS 208.67.220.220"
This should assist clients in reconfiguring their DNS settings to use the VPN tunnel for as the default gateway.
By default, the OpenVPN server uses port 1194 and the UDP protocol to accept client connections. If you need to use a different port because of restrictive network environments that your clients might be in, you can change the port
option. If you are not hosting web content your OpenVPN server, port 443 is a popular choice since this is usually allowed through firewall rules.
# Optional!
port 443
Often if the protocol will be restricted to that port as well. If so, change proto
from UDP to TCP:
# Optional!
proto tcp
If you have no need to use a different port, it is best to leave these two settings as their default.
If you selected a different name during the ./build-key-server
command earlier, modify the cert
and key
lines that you see to point to the appropriate .crt
and .key
files. If you used the default server
, this should already be set correctly:
cert server.crt
key server.key
When you are finished, save and close the file.
Next, we need to adjust some aspects of the server’s networking so that OpenVPN can correctly route traffic.
First, we need to allow the server to forward traffic. This is fairly essential to the functionality we want our VPN server to provide.
We can adjust this setting by modifying the /etc/sysctl.conf
file:
Inside, look for the line that sets net.ipv4.ip_forward
. Remove the “#” character from the beginning of the line to uncomment that setting:
net.ipv4.ip_forward=1
Save and close the file when you are finished.
To read the file and adjust the values for the current session, type:
If you followed the Ubuntu 16.04 initial server setup guide in the prerequisites, you should have the UFW firewall in place. Regardless of whether you use the firewall to block unwanted traffic (which you almost always should do), we need the firewall in this guide to manipulate some of the traffic coming into the server. We need to modify the rules file to set up masquerading, an iptables
concept that provides on-the-fly dynamic NAT to correctly route client connections.
Before we open the firewall configuration file to add masquerading, we need to find the public network interface of our machine. To do this, type:
Your public interface should follow the word “dev”. For example, this result shows the interface named wlp11s0
, which is highlighted below:
Outputdefault via 203.0.113.1 dev wlp11s0 proto static metric 600
When you have the interface associated with your default route, open the /etc/ufw/before.rules
file to add the relevant configuration:
This file handles configuration that should be put into place before the conventional UFW rules are loaded. Towards the top of the file, add the highlighted lines below. This will set the default policy for the POSTROUTING
chain in the nat
table and masquerade any traffic coming from the VPN:
Note: Remember to replace wlp11s0
in the -A POSTROUTING
line below with the interface you found in the above command.
#
# rules.before
#
# Rules that should be run before the ufw command line added rules. Custom
# rules should be added to one of these chains:
# ufw-before-input
# ufw-before-output
# ufw-before-forward
#
# START OPENVPN RULES
# NAT table rules
*nat
:POSTROUTING ACCEPT [0:0]
# Allow traffic from OpenVPN client to wlp11s0 (change to the interface you discovered!)
-A POSTROUTING -s 10.8.0.0/8 -o wlp11s0 -j MASQUERADE
COMMIT
# END OPENVPN RULES
# Don't delete these required lines, otherwise there will be errors
*filter
. . .
Save and close the file when you are finished.
We need to tell UFW to allow forwarded packets by default as well. To do this, we will open the /etc/default/ufw
file:
Inside, find the DEFAULT_FORWARD_POLICY
directive. We will change the value from DROP
to ACCEPT
:
DEFAULT_FORWARD_POLICY="ACCEPT"
Save and close the file when you are finished.
Next, we’ll adjust the firewall itself to allow traffic to OpenVPN.
If you did not change the port and protocol in the /etc/openvpn/server.conf
file, you will need to open up UDP traffic to port 1194. If you modified the port and/or protocol, substitute the values you selected here.
We’ll also add the SSH port in case you forgot to add it when following the prerequisite tutorial:
Now, we can disable and re-enable UFW to load the changes from all of the files we’ve modified:
Our server is now configured to correctly handle OpenVPN traffic.
We’re finally ready to start the OpenVPN service on our server. We can do this using systemd.
We need to start the OpenVPN server by specifying our configuration file name as an instance variable after the systemd unit file name. Our configuration file for our server is called /etc/openvpn/server.conf
, so we will add @server
to end of our unit file when calling it:
Double-check that the service has started successfully by typing:
If everything went well, your output should look something that looks like this:
Output● openvpn@server.service - OpenVPN connection to server
Loaded: loaded (/lib/systemd/system/openvpn@.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2016-05-03 15:30:05 EDT; 47s ago
Docs: man:openvpn(8)
https://community.openvpn.net/openvpn/wiki/Openvpn23ManPage
https://community.openvpn.net/openvpn/wiki/HOWTO
Process: 5852 ExecStart=/usr/sbin/openvpn --daemon ovpn-%i --status /run/openvpn/%i.status 10 --cd /etc/openvpn --script-security 2 --config /etc/openvpn/%i.conf --writepid /run/openvpn/%i.pid (code=exited, sta
Main PID: 5856 (openvpn)
Tasks: 1 (limit: 512)
CGroup: /system.slice/system-openvpn.slice/openvpn@server.service
└─5856 /usr/sbin/openvpn --daemon ovpn-server --status /run/openvpn/server.status 10 --cd /etc/openvpn --script-security 2 --config /etc/openvpn/server.conf --writepid /run/openvpn/server.pid
May 03 15:30:05 openvpn2 ovpn-server[5856]: /sbin/ip addr add dev tun0 local 10.8.0.1 peer 10.8.0.2
May 03 15:30:05 openvpn2 ovpn-server[5856]: /sbin/ip route add 10.8.0.0/24 via 10.8.0.2
May 03 15:30:05 openvpn2 ovpn-server[5856]: GID set to nogroup
May 03 15:30:05 openvpn2 ovpn-server[5856]: UID set to nobody
May 03 15:30:05 openvpn2 ovpn-server[5856]: UDPv4 link local (bound): [undef]
May 03 15:30:05 openvpn2 ovpn-server[5856]: UDPv4 link remote: [undef]
May 03 15:30:05 openvpn2 ovpn-server[5856]: MULTI: multi_init called, r=256 v=256
May 03 15:30:05 openvpn2 ovpn-server[5856]: IFCONFIG POOL: base=10.8.0.4 size=62, ipv6=0
May 03 15:30:05 openvpn2 ovpn-server[5856]: IFCONFIG POOL LIST
May 03 15:30:05 openvpn2 ovpn-server[5856]: Initialization Sequence Completed
You can also check that the OpenVPN tun0
interface is available by typing:
You should see a configured interface:
Output4: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 100
link/none
inet 10.8.0.1 peer 10.8.0.2/32 scope global tun0
valid_lft forever preferred_lft forever
If everything went well, enable the service so that it starts automatically at boot:
Next, we need to set up a system that will allow us to create client configuration files easily.
Create a directory structure within your home directory to store the files:
Since our client configuration files will have the client keys embedded, we should lock down permissions on our inner directory:
Next, let’s copy an example client configuration into our directory to use as our base configuration:
Open this new file in your text editor:
Inside, we need to make a few adjustments.
First, locate the remote
directive. This points the client to our OpenVPN server address. This should be the public IP address of your OpenVPN server. If you changed the port that the OpenVPN server is listening on, change 1194
to the port you selected:
. . .
# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote server_IP_address 1194
. . .
Be sure that the protocol matches the value you are using in the server configuration:
proto udp
Next, uncomment the user
and group
directives by removing the “;”:
# Downgrade privileges after initialization (non-Windows only)
user nobody
group nogroup
Find the directives that set the ca
, cert
, and key
. Comment out these directives since we will be adding the certs and keys within the file itself:
# SSL/TLS parms.
# See the server config file for more
# description. It's best to use
# a separate .crt/.key file pair
# for each client. A single ca
# file can be used for all clients.
#ca ca.crt
#cert client.crt
#key client.key
Mirror the cipher
and auth
settings that we set in the /etc/openvpn/server.conf
file:
cipher AES-128-CBC
auth SHA256
Next, add the key-direction
directive somewhere in the file. This must be set to “1” to work with the server:
key-direction 1
Finally, add a few commented out lines. We want to include these with every config, but should only enable them for Linux clients that ship with a /etc/openvpn/update-resolv-conf
file. This script uses the resolvconf
utility to update DNS information for Linux clients.
# script-security 2
# up /etc/openvpn/update-resolv-conf
# down /etc/openvpn/update-resolv-conf
If your client is running Linux and has an /etc/openvpn/update-resolv-conf
file, you should uncomment these lines from the generated OpenVPN client configuration file.
Save the file when you are finished.
Next, we will create a simple script to compile our base configuration with the relevant certificate, key, and encryption files. This will place the generated configuration in the ~/client-configs/files
directory.
Create and open a file called make_config.sh
within the ~/client-configs
directory:
Inside, paste the following script:
Save and close the file when you are finished.
Mark the file as executable by typing:
Now, we can easily generate client configuration files.
If you followed along with the guide, you created a client certificate and key called client1.crt
and client1.key
respectively by running the ./build-key client1
command in step 6. We can generate a config for these credentials by moving into our ~/client-configs
directory and using the script we made:
If everything went well, we should have a client1.ovpn
file in our ~/client-configs/files
directory:
Outputclient1.ovpn
We need to transfer the client configuration file to the relevant device. For instance, this could be your local computer or a mobile device.
While the exact applications used to accomplish this transfer will depend on your choice and device’s operating system, you want the application to use SFTP (SSH file transfer protocol) or SCP (Secure Copy) on the backend. This will transport your client’s VPN authentication files over an encrypted connection.
Here is an example SFTP command using our client1.ovpn example. This command can be run from your local computer (OS X or Linux). It places the .ovpn
file in your home directory:
Here are several tools and tutorials for securely transferring files from the server to a local computer:
Now, we’ll discuss how to install a client VPN profile on Windows, OS X, iOS, and Android. None of these client instructions are dependent on one another, so feel free to skip to whichever is applicable to you.
The OpenVPN connection will be called whatever you named the .ovpn
file. In our example, this means that the connection will be called client1.ovpn
for the first client file we generated.
Installing
The OpenVPN client application for Windows can be found on OpenVPN’s Downloads page. Choose the appropriate installer version for your version of Windows.
Note
OpenVPN needs administrative privileges to install.
After installing OpenVPN, copy the .ovpn
file to:
C:\Program Files\OpenVPN\config
When you launch OpenVPN, it will automatically see the profile and makes it available.
OpenVPN must be run as an administrator each time it’s used, even by administrative accounts. To do this without having to right-click and select Run as administrator every time you use the VPN, you can preset this, but this must be done from an administrative account. This also means that standard users will need to enter the administrator’s password to use OpenVPN. On the other hand, standard users can’t properly connect to the server unless the OpenVPN application on the client has admin rights, so the elevated privileges are necessary.
To set the OpenVPN application to always run as an administrator, right-click on its shortcut icon and go to Properties. At the bottom of the Compatibility tab, click the button to Change settings for all users. In the new window, check Run this program as an administrator.
Connecting
Each time you launch the OpenVPN GUI, Windows will ask if you want to allow the program to make changes to your computer. Click Yes. Launching the OpenVPN client application only puts the applet in the system tray so that the VPN can be connected and disconnected as needed; it does not actually make the VPN connection.
Once OpenVPN is started, initiate a connection by going into the system tray applet and right-clicking on the OpenVPN applet icon. This opens the context menu. Select client1 at the top of the menu (that’s our client1.ovpn
profile) and choose Connect.
A status window will open showing the log output while the connection is established, and a message will show once the client is connected.
Disconnect from the VPN the same way: Go into the system tray applet, right-click the OpenVPN applet icon, select the client profile and click Disconnect.
Installing
Tunnelblick is a free, open source OpenVPN client for Mac OS X. You can download the latest disk image from the Tunnelblick Downloads page. Double-click the downloaded .dmg
file and follow the prompts to install.
Towards the end of the installation process, Tunnelblick will ask if you have any configuration files. It can be easier to answer No and let Tunnelblick finish. Open a Finder window and double-click client1.ovpn
. Tunnelblick will install the client profile. Administrative privileges are required.
Connecting
Launch Tunnelblick by double-clicking Tunnelblick in the Applications folder. Once Tunnelblick has been launched, there will be a Tunnelblick icon in the menu bar at the top right of the screen for controlling connections. Click on the icon, and then the Connect menu item to initiate the VPN connection. Select the client1 connection.
If you are using Linux, there are a variety of tools that you can use depending on your distribution. Your desktop environment or window manager might also include connection utilities.
The most universal way of connecting, however, is to just use the OpenVPN software.
On Ubuntu or Debian, you can install it just as you did on the server by typing:
On CentOS you can enable the EPEL repositories and then install it by typing:
Check to see if your distribution includes a /etc/openvpn/update-resolv-conf
script:
Outputupdate-resolve-conf
Next, edit the OpenVPN client configuration file you transfered:
Uncomment the three lines we placed in to adjust the DNS settings if you were able to find an update-resolv-conf
file:
script-security 2
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf
If you are using CentOS, change the group
from nogroup
to nobody
to match the distribution’s available groups:
group nobody
Save and close the file.
Now, you can connect to the VPN by just pointing the openvpn
command to the client configuration file:
This should connect you to your server.
Installing
From the iTunes App Store, search for and install OpenVPN Connect, the official iOS OpenVPN client application. To transfer your iOS client configuration onto the device, connect it directly to a computer.
Completing the transfer with iTunes will be outlined here. Open iTunes on the computer and click on iPhone > apps. Scroll down to the bottom to the File Sharing section and click the OpenVPN app. The blank window to the right, OpenVPN Documents, is for sharing files. Drag the .ovpn
file to the OpenVPN Documents window.
Now launch the OpenVPN app on the iPhone. There will be a notification that a new profile is ready to import. Tap the green plus sign to import it.
Connecting
OpenVPN is now ready to use with the new profile. Start the connection by sliding the Connect button to the On position. Disconnect by sliding the same button to Off.
Note
The VPN switch under Settings cannot be used to connect to the VPN. If you try, you will receive a notice to only connect using the OpenVPN app.
Installing
Open the Google Play Store. Search for and install Android OpenVPN Connect, the official Android OpenVPN client application.
The .ovpn
profile can be transferred by connecting the Android device to your computer by USB and copying the file over. Alternatively, if you have an SD card reader, you can remove the device’s SD card, copy the profile onto it and then insert the card back into the Android device.
Start the OpenVPN app and tap the menu to import the profile.
Then navigate to the location of the saved profile (the screenshot uses /sdcard/Download/
) and select the file. The app will make a note that the profile was imported.
Connecting
To connect, simply tap the Connect button. You’ll be asked if you trust the OpenVPN application. Choose OK to initiate the connection. To disconnect from the VPN, go back to the OpenVPN app and choose Disconnect.
Once everything is installed, a simple check confirms everything is working properly. Without having a VPN connection enabled, open a browser and go to DNSLeakTest.
The site will return the IP address assigned by your internet service provider and as you appear to the rest of the world. To check your DNS settings through the same website, click on Extended Test and it will tell you which DNS servers you are using.
Now connect the OpenVPN client to your Droplet’s VPN and refresh the browser. The completely different IP address of your VPN server should now appear. That is now how you appear to the world. Again, DNSLeakTest’s Extended Test will check your DNS settings and confirm you are now using the DNS resolvers pushed by your VPN.
Occasionally, you may need to revoke a client certificate to prevent further access to the OpenVPN server.
To do so, enter your CA directory and re-source the vars
file:
Next, call the revoke-full
command using the client name that you wish to revoke:
This will show some output, ending in error 23
. This is normal and the process should have successfully generated the necessary revocation information, which is stored in a file called crl.pem
within the keys
subdirectory.
Transfer this file to the /etc/openvpn
configuration directory:
Next, open the OpenVPN server configuration file:
At the bottom of the file, add the crl-verify
option, so that the OpenVPN server checks the certificate revocation list that we’ve created each time a connection attempt is made:
crl-verify crl.pem
Save and close the file.
Finally, restart OpenVPN to implement the certificate revocation:
The client should now longer be able to successfully connect to the server using the old credential.
To revoke additional clients, follow this process:
vars
file in the ~/openvpn-ca
directory and then calling the revoke-full
script on the client name./etc/openvpn
directory to overwrite the old list.This process can be used to revoke any certificates that you’ve previously issued for your server.
Congratulations! You are now securely traversing the internet protecting your identity, location, and traffic from snoopers and censors.
To configure more clients, you only need to follow steps 6, and 11-13 for each additional device. To revoke access to clients, follow step 14.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Thanks! BTW, if not working for some one this script may do the trick: https://github.com/Nyr/openvpn-install
Hey, how secure is this? How do we know it’s not adding some funny logging/calling home setup in the background?
Sorry about the noob question.
You can view source of this script obviously.
Thanks, your open-vpn installed worked flawlessly on Digital Ocean. I couldn’t get the step-by-step running (my ip route | grep default kept reporting eth0 as my public interface - think that was a problem). In any event, OpenVPN on PC connected no worries.
yeah thanks the script works perfect for me too. I’ve tipped you also. I was not able to get things working by following the guide here (to the letter!), so you’ve been really helpful :)
I’ve followed this tutorial step by step and managed to install and connect to the VPN, however after I was connected I couldn’t do anything except ssh to server ip. After using the script you provided everything works okay, thanks :)
(Also I’m writing this from the server)
Thank god for this script… after doing this 100 times over and over again and it not working, tried your script worked right away lol my issue was : Mar 24 15:24:15 bradVPN ovpn-server[2236]: 152.233.21.22:13901 TLS Error: reading acknowledgement record from packet
wow, I spent hours on above tutorial, not sure where I went wrong but it didn’t work for me at step 11 (error: line 21: -----END: command not found ./make_config.sh: line 36: /dev/fd/63: Permission denied, tried sudo, same)
This script worked perfectly!! All these in less than a minute! Thank you so much!!
After I started a new droplet, this worked flawlessly. I tried for three frikkin days… Forget RTFM. RTFC
There’s something wrong with this tutorial somewhere. Been trying to setup using this tutorial to the letter but after countless retries, I finally gave up and used the script above. Took only seconds. Thank you!
Worked PERFECTLY. After installing it, just tweak ufw, etc.
Thank you very much!
how can I run the script on the server?
hi I run an OpenVpn service on my Ubuntu VPS by following this article. service is activate successfully. but I can’t connect to that by my client Debian machine. the connection failed error is here:
ERROR: Private key password verification failed. Exiting due to fatal error.
This ran just fine. My question is, how do you then generate the file for iphone?
I’m talking about the ovpn file. The VPN is running, but now how to do the ovpn generation?
This comment has been deleted
At last it works!) Thanks for the script. I tried following this tutorial step by step before but didn’t succeed.
The tutorial is great if you want to learn all of the steps needed to run a VPN and client but if you need a VPN now and don’t care much about the technical aspects the openvpn-install on github is the way to go. The tutorial took me about an hour whereas the script ran in all of (1) minute and if you look at the script it does the same thing with no guess work. Thanks to gammx1 for pointing this script out. Use it, it works and don’t forget to donate it’s worth your time.
how can I run the script on the server?
hi I run an OpenVpn service on my Ubuntu VPS by following this article. service is activate successfully. but I can’t connect to that by my client Debian machine. the connection failed error is here:
ERROR: Private key password verification failed. Exiting due to fatal error.
This ran just fine. My question is, how do you then generate the file for iphone?
I’m talking about the ovpn file. The VPN is running, but now how to do the ovpn generation?
This comment has been deleted
At last it works!) Thanks for the script. I tried following this tutorial step by step before but didn’t succeed.
The tutorial is great if you want to learn all of the steps needed to run a VPN and client but if you need a VPN now and don’t care much about the technical aspects the openvpn-install on github is the way to go. The tutorial took me about an hour whereas the script ran in all of (1) minute and if you look at the script it does the same thing with no guess work. Thanks to gammx1 for pointing this script out. Use it, it works and don’t forget to donate it’s worth your time.
how can I run the script on the server?
hi I run an OpenVpn service on my Ubuntu VPS by following this article. service is activate successfully. but I can’t connect to that by my client Debian machine. the connection failed error is here:
ERROR: Private key password verification failed. Exiting due to fatal error.
This ran just fine. My question is, how do you then generate the file for iphone?
I’m talking about the ovpn file. The VPN is running, but now how to do the ovpn generation?
This comment has been deleted
At last it works!) Thanks for the script. I tried following this tutorial step by step before but didn’t succeed.
The tutorial is great if you want to learn all of the steps needed to run a VPN and client but if you need a VPN now and don’t care much about the technical aspects the openvpn-install on github is the way to go. The tutorial took me about an hour whereas the script ran in all of (1) minute and if you look at the script it does the same thing with no guess work. Thanks to gammx1 for pointing this script out. Use it, it works and don’t forget to donate it’s worth your time.
Works great, thanks !!
But if I want more than one client to connect, how do I create login for another one?
@rasmusj78: You can repeat step 6 and 11-13 for any additional clients.
Thanks :-)
At first shot, i got my openvpn server running perfrectly but now i am trying to add another clients, but i couldnt do it. i generated another certificate for another client but it didnt work again. Probably its a simple mistake that i repeat, what can it be? Thank you.
Thanks for making an updated guide for the new LTS release!!
If anyone else is having trouble with iOS setup using OpenVPN Connect, you need to remove all of the [inline] options (ca, cert, key, tls-auth) and just leave the embedded certificates there. I chose to just comment the lines out in the config, but you can delete them as well.
I think I’m having this issue, iOS devices “connect” to the VPN, but the IP addresses are not changed.
I can connect successfully on my laptop, but not on iOS. I tried to delete the inline options, but that seems to have broken the ovpn file. Any help would be awesome.
Ok, I’ve fixed it. It was a different issue, I needed to route all client traffic through the VPN. Simple enough to add:
push “redirect-gateway def1”
To the server.conf.
You could also use this, deploy an OpenVPN Endpoint with a single command. https://github.com/ttlequals0/autovpn
If you want a GUI – Pritunl is great also, as is OpenVPN Access Server.
OpenVPN still defaults to BF-CBC which hasn’t been broken yet but as a good practice it would be best to use AES-128-CBC; you will at least get an advantage since many CPUs hardware optimize AES, not to mention it’s got more eyeballs looking at it and is ‘battle hardened’.
Using the additional directive “auth SHA256” will use SHA2 instead of SHA1 for message authentication; the latter is now considered cryptographically broken.
More hardening tips: https://blog.g3rt.nl/openvpn-security-tips.html
Thanks for linking my article. :)
By the way,
BF-CBC (Blowfish) is broken too now, because Blowfish, amongst other 64-bit block ciphers, is affected by the SWEET32 attack. https://tech.slashdot.org/story/16/08/27/186213/new-sweet32-crypto-attacks-speed-up-deprecation-of-3des-blowfish
The reason for OpenVPN still using BF-CBC as default cipher (and SHA-1 for message authentication) is the compatibility with older OpenVPN software. Fortunately OpenVPN protocol will support cipher/auth negotiation which allows this while maintaining support with older releases. https://community.openvpn.net/openvpn/wiki/StatusOfOpenvpn24
Great tutorial…on my Androids I am getting “Error reading multiple files referenced by profile: [inline], [inline], [inline], [inline]”…how can I correct that?
@cyptex01: Yeah, some clients don’t like the
[inline]
syntax. I’ve remove them since most implementations don’t really seem to need them. Thanks for the heads up!is there a solution if the net provider here prevents UDP connection ?
I’ve strictly followed this guide on a newly crested Ubuntu 16.04 system, altough I had to leave out the [inline] directives (I commented out those lines) to be able to get the ovpn profile working on iOS. I can now succesfully set up a connection from an iPad to the server, however once OpenVPN is connected, I can’t actually browse the web. The syslog en ufw.log files don’t seem to report anything unexpected. How can I best approach debugging this issue?
I’ve solved this by using ens3 instead of eth0 in the before.rules config.
@InspireNL: Glad you figured it out! I’ve updated the tutorial to include finding the server’s correct public interface so that people hopefully won’t run into that next time. Thanks for sharing the solution.
Thanks!
Can you add a Username & Password to the openvpn config? So that not everyone can logon who has the config
Great tutorial. However, I have a couple of suggestions that I think are very important. First, you should note that if you use a name other than “server”, you will have to change information in the server’s config file in order to get up and running by pointing to the correct .key and .crt files. OpenVPN will fail to start if you do not do so.
The other suggestion is related to the order in which you give instructions when setting up routing. You should be getting the interface name before even going into the ufw rules. It doesn’t really make sense to open the file, edit it, exit and save the file, use the command to find interface name, go back into file, edit it and then save it again. Interface name > Edit File > Save file and done.
Thanks for taking the time to create this tutorial!!!
I’m kind of confused here. Tried to setup OpenVPN on an Ubuntu server 16.04 using this guide except I used 443/tcp for the vpn port. I got the .ovpn file on my phone and it connects fine but does not load any web pages. Help is much appreciated.
I’m having the same problem as gecko40. Followed the instructions, but specified tcp on the default port instead of udp. I can connect fine, just can’t view any web pages. Any ideas?
Check forwarding rules by UFW and sysctl. And of course check logs.
On OS X with an iOS device you can also AirDrop the
client1.ovpn
file and open it in OpenVPN Client on the phone/tablet. A little easier than iTunes transferFor those experiencing dnsleaks, if found appending these three lines into the .ovpn file fixed it: script-security 2 up /etc/openvpn/update-resolv-conf down /etc/openvpn/update-resolv-conf
Thank you for your comment, I had some DNS leaks and this was the exact solution to my problems
This comment has been deleted
I am in China at the moment. It’s working mostly as expected: I can access youtube, facebook, etc. If I go to Wolfram Alpha and ask “where am I” it would give me the VPN server location, as expected. But if I go to skype.com, I’d get forwarded to their Chinese site. I am on a Mac and I have tried several browsers. They all forwarded me to the Chinese site. How does skype know that I am in China? I thought all traffic in VPN goes through the VPN server. Using Pure OpenVPN: http://www.bestvpnprovider.com/china-vpn/
Maybe it redirects you based on info from your account? Try to create new one.
This is a very nice howto and I could configure the server and client without many trouble. However, I do not want the client traffics be redirected through the VPN, but only the client to be able to connect to each other through the VPN, while accessing internet directly from their respective connections.
I commented back the “push” instructions and uncommented the “client-to-client” one, but to no avail…
How should I do?
Comment:
push “redirect-gateway def1 bypass-dhcp”
But even w/o it some GUI clients can add vpn-route as default one.
I have TLS problem when I try to connect Windows 10 client to my ubuntu openvpn server.
See my problem there: http://askubuntu.com/questions/785537/openvpn-tls-handshake-failed-with-linux-server-windows-client
Can someone help me?
I was having the same issue, it turns out that beside allowing the port in
ufw
it also has to be allowed in the new DO Cloud Firewall if enabled. @jellingwood is there a way you can redirect this note to DO so they can somehow put a mention of this in the tutorial?i have the same problem after i had format my PC. I tried that;
“https://openvpn.net/index.php/open-source/faq/79-client/253-tls-error-tls-key-negotiation-failed-to-occur-within-60-seconds-check-your-network-connectivity.html”
But the problem wasn’t solved. Also i am connecting openvpn server without any problem by my phone and work PC(Windows 10)
Can you help me?
i found the solution. The problem is Kaspersky Anti Ransomware Tool for Business. I uninstalled it and openvpn connection established without problem.
Sure I agree but i like to use this coupon code vpn site.
Thank you for the incredible guide! It was easy to get my OpenVPN server up and running.
Quick question… Is there a configuration somewhere to have OpenVPN prevent clients from accessing the local network? I would like to forward internet traffic only.
Is possible to enable and use IPv6 ? My internet connection dont have IPv6, but I wish to use Digital Ocean as IPv6 tunnel.
I need the exact same thing. Did you manage to get IPv6 via a VPN? edit: I just found a comment from Vitalik explaining how to enable IPv6 and it works :)
i have all install finish , when i configer in client pc in windows 8 then all ok connection 10.8.0.6 but not working web pages i think this my problems in ufw can you tell me if i ufw off this then also not working ?
I followed these and now I can’t connect my server via ssh :)
I have the same problem. Have you found a solution?
The only way to do it I found is to use “Access console” option in DO control panel. But I need to allow password (not CA) access for SSH user, that’s bad. I think the problem is somewhere in routing/firewall configuration.
Commented out all new lines in /etc/ufw/before.rules and ALL now works. Do I really need them?..
The issue is is because the commands reset the firewall and only the ports for the VPN are opened.
There is no way to recover the VPS, you will need to destroy it and start over again.
When you reach the stage of the ufw commands, after disabling and enabling the ufw, run these commands to regain access again to SSH:
sudo ufw allow 22/tcp sudo ufw allow 22/udp
That should restore the SSH connection, if you are still connected to the VPS.
Thank you very much for your excellent guide. It was easy to get my OpenVPN server up and running. How to set static IP Addresses for clients?
I’m keep getting “openvpn@server.service failed because the control process exited with error code” When I tried to start the server. can you please help…???
Thank for guide… When i create client1 , client2 and client3 Now i jus need 2 client… Can i remove client3… If can, how to remove it… This my first time install ovpn… Before that using pritunl…
@weethai Hello! Good question.
To revoke OpenVPN access for a certificate you’ve signed, first you’ll need to go to the CA directory you created and re-source the
vars
file:Afterwards, you can call the
revoke-full
command with the client you wish to revoke:This will show some output, ending in
error 23
. This is normal, so don’t worry. This will generate a certificate revocation list in thekeys
subdirectory calledcrl.pem
.Transfer this file to your OpenVPN configuration directory:
Now, open the OpenVPN server configuration file:
At the bottom of the file, add this line so that the server checks client connections against the generated certificate revocation list each time:
Save and close the file.
Restart OpenVPN to implement the changes:
Your client should now no longer have access to make new connections to the OpenVPN server.
To revoke additional clients, you will need to:
vars
file in the~/openvpn-ca
directory and then calling therevoke-full
script on the client name./etc/openvpn
Hope that helps.
Thank… I did it… Now i trying using auth passwaord… In the cert i remove all cliet cert… jus using user n pass to conect… Any it work well… Also jus a few second to remove user… Using webmin to add user … Sorry my poor language…
Thank you for putting this together. Excellent how to, the install and configuration went without a hitch!
Step 6: Generate a Client Certificate and Key Pair suggests that we can generate client certs on client machines or a local administrator’s machine, then sign the cert with the server/CA cert. Can you provide some instruction on how to do this in the context of the how to, if we choose to go the more “complicated” route for security reasons?
Thanks again, all the DigitalOcean documentation is great!
Nice article! Btw I wasn’t able to ssh to my freshly spun server after following this tutorial, found out that the ufw only allows UDP connection thus blocking any new ssh connection. Need to execute
ufw allow ssh
via web console.Update: Tried to connect via ios device but got
connection timeout
from OpenVPN appServer log:
Should I be running
./clean-all
every time I login to create new client certs? Or is that something we do once in the very beginning? The~/openvpn-ca/keys
folder is growing, and I just want to make sure that I’m not supposed to be cleaning it out periodically.@scottie Good question. No, you should not be doing that. The
./clean-all
will remove all of the contents from your~/openvpn-ca/keys
directory, which includes all of your CA information. Granted, since OpenVPN only pays attention to the files we copy, your setup would still work. However, it might lead to breakage down the road as you try to revoke keys that no longer exist, etc. You should only run the./clean-all
script if you want to start over from scratch.Hey,
I’m actually setting up the VPN in my ubuntu vm. It does not support systemctl command that comes in step 9. Im really a noobie to this linux world, can anyone help me about an alternative for this? Stuck at this point and not able to move forward. Thanks!!
@hulkbuster: If the
systemctl
command is not available, that’s almost always a sign that you are trying to complete this guide using a different, incompatible version of Ubuntu. If you happen to be using Ubuntu 14.04, this guide would probably work out better for you.@jellingwood : Thanks!! itz working super fyn!!
Is possible to enable and use IPv6 ? My internet connection dont have IPv6, but I wish to use Digital Ocean as IPv6 tunnel.
I need the exact same thing. Did you manage to get IPv6 via a VPN? edit: I just found a comment from Vitalik explaining how to enable IPv6 and it works :)
i have all install finish , when i configer in client pc in windows 8 then all ok connection 10.8.0.6 but not working web pages i think this my problems in ufw can you tell me if i ufw off this then also not working ?
I followed these and now I can’t connect my server via ssh :)
I have the same problem. Have you found a solution?
The only way to do it I found is to use “Access console” option in DO control panel. But I need to allow password (not CA) access for SSH user, that’s bad. I think the problem is somewhere in routing/firewall configuration.
Commented out all new lines in /etc/ufw/before.rules and ALL now works. Do I really need them?..
The issue is is because the commands reset the firewall and only the ports for the VPN are opened.
There is no way to recover the VPS, you will need to destroy it and start over again.
When you reach the stage of the ufw commands, after disabling and enabling the ufw, run these commands to regain access again to SSH:
sudo ufw allow 22/tcp sudo ufw allow 22/udp
That should restore the SSH connection, if you are still connected to the VPS.
Thank you very much for your excellent guide. It was easy to get my OpenVPN server up and running. How to set static IP Addresses for clients?
I’m keep getting “openvpn@server.service failed because the control process exited with error code” When I tried to start the server. can you please help…???
Thank for guide… When i create client1 , client2 and client3 Now i jus need 2 client… Can i remove client3… If can, how to remove it… This my first time install ovpn… Before that using pritunl…
@weethai Hello! Good question.
To revoke OpenVPN access for a certificate you’ve signed, first you’ll need to go to the CA directory you created and re-source the
vars
file:Afterwards, you can call the
revoke-full
command with the client you wish to revoke:This will show some output, ending in
error 23
. This is normal, so don’t worry. This will generate a certificate revocation list in thekeys
subdirectory calledcrl.pem
.Transfer this file to your OpenVPN configuration directory:
Now, open the OpenVPN server configuration file:
At the bottom of the file, add this line so that the server checks client connections against the generated certificate revocation list each time:
Save and close the file.
Restart OpenVPN to implement the changes:
Your client should now no longer have access to make new connections to the OpenVPN server.
To revoke additional clients, you will need to:
vars
file in the~/openvpn-ca
directory and then calling therevoke-full
script on the client name./etc/openvpn
Hope that helps.
Thank… I did it… Now i trying using auth passwaord… In the cert i remove all cliet cert… jus using user n pass to conect… Any it work well… Also jus a few second to remove user… Using webmin to add user … Sorry my poor language…
Thank you for putting this together. Excellent how to, the install and configuration went without a hitch!
Step 6: Generate a Client Certificate and Key Pair suggests that we can generate client certs on client machines or a local administrator’s machine, then sign the cert with the server/CA cert. Can you provide some instruction on how to do this in the context of the how to, if we choose to go the more “complicated” route for security reasons?
Thanks again, all the DigitalOcean documentation is great!
Nice article! Btw I wasn’t able to ssh to my freshly spun server after following this tutorial, found out that the ufw only allows UDP connection thus blocking any new ssh connection. Need to execute
ufw allow ssh
via web console.Update: Tried to connect via ios device but got
connection timeout
from OpenVPN appServer log:
Should I be running
./clean-all
every time I login to create new client certs? Or is that something we do once in the very beginning? The~/openvpn-ca/keys
folder is growing, and I just want to make sure that I’m not supposed to be cleaning it out periodically.@scottie Good question. No, you should not be doing that. The
./clean-all
will remove all of the contents from your~/openvpn-ca/keys
directory, which includes all of your CA information. Granted, since OpenVPN only pays attention to the files we copy, your setup would still work. However, it might lead to breakage down the road as you try to revoke keys that no longer exist, etc. You should only run the./clean-all
script if you want to start over from scratch.Hey,
I’m actually setting up the VPN in my ubuntu vm. It does not support systemctl command that comes in step 9. Im really a noobie to this linux world, can anyone help me about an alternative for this? Stuck at this point and not able to move forward. Thanks!!
@hulkbuster: If the
systemctl
command is not available, that’s almost always a sign that you are trying to complete this guide using a different, incompatible version of Ubuntu. If you happen to be using Ubuntu 14.04, this guide would probably work out better for you.Is possible to enable and use IPv6 ? My internet connection dont have IPv6, but I wish to use Digital Ocean as IPv6 tunnel.
I need the exact same thing. Did you manage to get IPv6 via a VPN? edit: I just found a comment from Vitalik explaining how to enable IPv6 and it works :)
i have all install finish , when i configer in client pc in windows 8 then all ok connection 10.8.0.6 but not working web pages i think this my problems in ufw can you tell me if i ufw off this then also not working ?
I followed these and now I can’t connect my server via ssh :)
I have the same problem. Have you found a solution?
The only way to do it I found is to use “Access console” option in DO control panel. But I need to allow password (not CA) access for SSH user, that’s bad. I think the problem is somewhere in routing/firewall configuration.
Thank you very much for your excellent guide. It was easy to get my OpenVPN server up and running. How to set static IP Addresses for clients?
I’m keep getting “openvpn@server.service failed because the control process exited with error code” When I tried to start the server. can you please help…???
Thank for guide… When i create client1 , client2 and client3 Now i jus need 2 client… Can i remove client3… If can, how to remove it… This my first time install ovpn… Before that using pritunl…
@weethai Hello! Good question.
To revoke OpenVPN access for a certificate you’ve signed, first you’ll need to go to the CA directory you created and re-source the
vars
file:Afterwards, you can call the
revoke-full
command with the client you wish to revoke:This will show some output, ending in
error 23
. This is normal, so don’t worry. This will generate a certificate revocation list in thekeys
subdirectory calledcrl.pem
.Transfer this file to your OpenVPN configuration directory:
Now, open the OpenVPN server configuration file:
At the bottom of the file, add this line so that the server checks client connections against the generated certificate revocation list each time:
Save and close the file.
Restart OpenVPN to implement the changes:
Your client should now no longer have access to make new connections to the OpenVPN server.
To revoke additional clients, you will need to:
vars
file in the~/openvpn-ca
directory and then calling therevoke-full
script on the client name./etc/openvpn
Hope that helps.
Thank you for putting this together. Excellent how to, the install and configuration went without a hitch!
Step 6: Generate a Client Certificate and Key Pair suggests that we can generate client certs on client machines or a local administrator’s machine, then sign the cert with the server/CA cert. Can you provide some instruction on how to do this in the context of the how to, if we choose to go the more “complicated” route for security reasons?
Thanks again, all the DigitalOcean documentation is great!
Nice article! Btw I wasn’t able to ssh to my freshly spun server after following this tutorial, found out that the ufw only allows UDP connection thus blocking any new ssh connection. Need to execute
ufw allow ssh
via web console.Update: Tried to connect via ios device but got
connection timeout
from OpenVPN appServer log:
Should I be running
./clean-all
every time I login to create new client certs? Or is that something we do once in the very beginning? The~/openvpn-ca/keys
folder is growing, and I just want to make sure that I’m not supposed to be cleaning it out periodically.@scottie Good question. No, you should not be doing that. The
./clean-all
will remove all of the contents from your~/openvpn-ca/keys
directory, which includes all of your CA information. Granted, since OpenVPN only pays attention to the files we copy, your setup would still work. However, it might lead to breakage down the road as you try to revoke keys that no longer exist, etc. You should only run the./clean-all
script if you want to start over from scratch.Hey,
I’m actually setting up the VPN in my ubuntu vm. It does not support systemctl command that comes in step 9. Im really a noobie to this linux world, can anyone help me about an alternative for this? Stuck at this point and not able to move forward. Thanks!!
@hulkbuster: If the
systemctl
command is not available, that’s almost always a sign that you are trying to complete this guide using a different, incompatible version of Ubuntu. If you happen to be using Ubuntu 14.04, this guide would probably work out better for you.Is possible to enable and use IPv6 ? My internet connection dont have IPv6, but I wish to use Digital Ocean as IPv6 tunnel.
I need the exact same thing. Did you manage to get IPv6 via a VPN? edit: I just found a comment from Vitalik explaining how to enable IPv6 and it works :)
i have all install finish , when i configer in client pc in windows 8 then all ok connection 10.8.0.6 but not working web pages i think this my problems in ufw can you tell me if i ufw off this then also not working ?
I followed these and now I can’t connect my server via ssh :)
I have the same problem. Have you found a solution?
The only way to do it I found is to use “Access console” option in DO control panel. But I need to allow password (not CA) access for SSH user, that’s bad. I think the problem is somewhere in routing/firewall configuration.
Thank you very much for your excellent guide. It was easy to get my OpenVPN server up and running. How to set static IP Addresses for clients?
I’m keep getting “openvpn@server.service failed because the control process exited with error code” When I tried to start the server. can you please help…???
Thank for guide… When i create client1 , client2 and client3 Now i jus need 2 client… Can i remove client3… If can, how to remove it… This my first time install ovpn… Before that using pritunl…
@weethai Hello! Good question.
To revoke OpenVPN access for a certificate you’ve signed, first you’ll need to go to the CA directory you created and re-source the
vars
file:Afterwards, you can call the
revoke-full
command with the client you wish to revoke:This will show some output, ending in
error 23
. This is normal, so don’t worry. This will generate a certificate revocation list in thekeys
subdirectory calledcrl.pem
.Transfer this file to your OpenVPN configuration directory:
Now, open the OpenVPN server configuration file:
At the bottom of the file, add this line so that the server checks client connections against the generated certificate revocation list each time:
Save and close the file.
Restart OpenVPN to implement the changes:
Your client should now no longer have access to make new connections to the OpenVPN server.
To revoke additional clients, you will need to:
vars
file in the~/openvpn-ca
directory and then calling therevoke-full
script on the client name./etc/openvpn
Hope that helps.
Thank you for putting this together. Excellent how to, the install and configuration went without a hitch!
Step 6: Generate a Client Certificate and Key Pair suggests that we can generate client certs on client machines or a local administrator’s machine, then sign the cert with the server/CA cert. Can you provide some instruction on how to do this in the context of the how to, if we choose to go the more “complicated” route for security reasons?
Thanks again, all the DigitalOcean documentation is great!
Nice article! Btw I wasn’t able to ssh to my freshly spun server after following this tutorial, found out that the ufw only allows UDP connection thus blocking any new ssh connection. Need to execute
ufw allow ssh
via web console.Update: Tried to connect via ios device but got
connection timeout
from OpenVPN appServer log:
Should I be running
./clean-all
every time I login to create new client certs? Or is that something we do once in the very beginning? The~/openvpn-ca/keys
folder is growing, and I just want to make sure that I’m not supposed to be cleaning it out periodically.@scottie Good question. No, you should not be doing that. The
./clean-all
will remove all of the contents from your~/openvpn-ca/keys
directory, which includes all of your CA information. Granted, since OpenVPN only pays attention to the files we copy, your setup would still work. However, it might lead to breakage down the road as you try to revoke keys that no longer exist, etc. You should only run the./clean-all
script if you want to start over from scratch.Hey,
I’m actually setting up the VPN in my ubuntu vm. It does not support systemctl command that comes in step 9. Im really a noobie to this linux world, can anyone help me about an alternative for this? Stuck at this point and not able to move forward. Thanks!!
@hulkbuster: If the
systemctl
command is not available, that’s almost always a sign that you are trying to complete this guide using a different, incompatible version of Ubuntu. If you happen to be using Ubuntu 14.04, this guide would probably work out better for you.Is possible to enable and use IPv6 ? My internet connection dont have IPv6, but I wish to use Digital Ocean as IPv6 tunnel.
I need the exact same thing. Did you manage to get IPv6 via a VPN? edit: I just found a comment from Vitalik explaining how to enable IPv6 and it works :)
i have all install finish , when i configer in client pc in windows 8 then all ok connection 10.8.0.6 but not working web pages i think this my problems in ufw can you tell me if i ufw off this then also not working ?
I followed these and now I can’t connect my server via ssh :)
I have the same problem. Have you found a solution?
The only way to do it I found is to use “Access console” option in DO control panel. But I need to allow password (not CA) access for SSH user, that’s bad. I think the problem is somewhere in routing/firewall configuration.
Thank you very much for your excellent guide. It was easy to get my OpenVPN server up and running. How to set static IP Addresses for clients?
I’m keep getting “openvpn@server.service failed because the control process exited with error code” When I tried to start the server. can you please help…???
Thank for guide… When i create client1 , client2 and client3 Now i jus need 2 client… Can i remove client3… If can, how to remove it… This my first time install ovpn… Before that using pritunl…
@weethai Hello! Good question.
To revoke OpenVPN access for a certificate you’ve signed, first you’ll need to go to the CA directory you created and re-source the
vars
file:Afterwards, you can call the
revoke-full
command with the client you wish to revoke:This will show some output, ending in
error 23
. This is normal, so don’t worry. This will generate a certificate revocation list in thekeys
subdirectory calledcrl.pem
.Transfer this file to your OpenVPN configuration directory:
Now, open the OpenVPN server configuration file:
At the bottom of the file, add this line so that the server checks client connections against the generated certificate revocation list each time:
Save and close the file.
Restart OpenVPN to implement the changes:
Your client should now no longer have access to make new connections to the OpenVPN server.
To revoke additional clients, you will need to:
vars
file in the~/openvpn-ca
directory and then calling therevoke-full
script on the client name./etc/openvpn
Hope that helps.
Thank you for putting this together. Excellent how to, the install and configuration went without a hitch!
Step 6: Generate a Client Certificate and Key Pair suggests that we can generate client certs on client machines or a local administrator’s machine, then sign the cert with the server/CA cert. Can you provide some instruction on how to do this in the context of the how to, if we choose to go the more “complicated” route for security reasons?
Thanks again, all the DigitalOcean documentation is great!
Nice article! Btw I wasn’t able to ssh to my freshly spun server after following this tutorial, found out that the ufw only allows UDP connection thus blocking any new ssh connection. Need to execute
ufw allow ssh
via web console.Update: Tried to connect via ios device but got
connection timeout
from OpenVPN appServer log:
Should I be running
./clean-all
every time I login to create new client certs? Or is that something we do once in the very beginning? The~/openvpn-ca/keys
folder is growing, and I just want to make sure that I’m not supposed to be cleaning it out periodically.@scottie Good question. No, you should not be doing that. The
./clean-all
will remove all of the contents from your~/openvpn-ca/keys
directory, which includes all of your CA information. Granted, since OpenVPN only pays attention to the files we copy, your setup would still work. However, it might lead to breakage down the road as you try to revoke keys that no longer exist, etc. You should only run the./clean-all
script if you want to start over from scratch.Hey,
I’m actually setting up the VPN in my ubuntu vm. It does not support systemctl command that comes in step 9. Im really a noobie to this linux world, can anyone help me about an alternative for this? Stuck at this point and not able to move forward. Thanks!!
@hulkbuster: If the
systemctl
command is not available, that’s almost always a sign that you are trying to complete this guide using a different, incompatible version of Ubuntu. If you happen to be using Ubuntu 14.04, this guide would probably work out better for you.This is the worst article I’ve seen from DigitalOcean.com, can you please get someone like James who wrote the OpenVPN installation on Ubuntu 14.04 (https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-14-04) to re-write this article??
If OpenVPN fails to start and gives you the error:
You’ll find the solution here at Ask Ubuntu
I was wondering if anyone knows how to audit OpenVPN connections? I’d like to understand how my OpenVPN server is being used, since I have multiple users accessing the server for VPN services. I’d like to understand things like who, when, how long, and any other details about the connect like IP addresses, etc. Thoughts? Thank you!
i have below errors, could someone help pls?
@xinhedanti: Check to see if any of the answers here help you fix the issue. Also, make sure that
key-direction
is set to “0” on the server and “1” on the clients.Very nice! I have a question: How can I redirect clients traffic only to a certain site, instead of all the internet traffic? for example: I want to redirect only the traffic to facebook.com, but all the other traffic does not go through the VPN. Thanks
Thanks for the tutorial :D
This comment has been deleted
After following this tutorial I lost SSH and SFTP access to my server. I followed the tutorial exactly, but I lost all access to my server and had to destroy it.
If you could please fix this tutorial so other people don’t lose their servers that would be great.
I found a fix: you need to manually re-add the SSH ports after modifying the firewall:
sudo ufw allow 22/tcp sudo ufw allow 22/udp
How do I add support for ipv6? My ipv6 address gets exposed since that isn’t being routed through the tunnel?
I was facing this problem when following the tutorial. May help some: http://serverfault.com/questions/521482/openvpn-server-not-forwarding-ping-traffic-from-tun0-to-eth0-for-rest-of-the-hos
I’m running windows client, should I be uncommenting out the user and group? I followed the tutorial, was able to connect with openvpn, but without internet access after connection. Help?
I have tried many so called tutorials for OpenVPN this works.
Thank You!
Hello my computer is on Ubuntu, how can I use the ovpn file on my Ubuntu to connect to my VPN droplet?
I followed this guide to the T I was logged in under root when I did this guide… when i got to the end to copy the file over from my ubuntu server using mac OS X terminal using sftp - i ran the command but it said no such file or directory - I then moved the opencpv.conf from where it was under some folder under the root and moved it to /home/ronnie etc… and it created the directory and it moved the file.
I was able to get it copied over to my mac book pro using the sftp command. but when I open the openvpn file using tunnel block - it doesn’t connect and the log on tunnel block shows
http://drops.articulate.com/ho1o
File will self-destruct in 1 week… Also, I’m very new to ubuntu and all of this please bare with me and if there is info in the log that show;d not be showing please let me know ASAP
Thanks Ronnie
While executing command: sudo systemctl start openvpn@server
I got error :
Failed to start openvpn@server.service: Unknown unit: openvpn@server.service See system logs and ‘systemctl status openvpn@server.service’ for details.
Please help. Thank you.
Getting error in the begining after build-key-server:
Hi. Good Tutorial. I would like to setup openvpn for this scenario: I will have 10 droplets with their external(public) interfaces disabled. I need an openvpn configuration that only tunnels traffic to those droplets, not to the internet. What changes need to be made to the configuration on the tutorial?
Thank you for the useful guide.
Just a small point, if you have not followed the “Initial Server Setup with Ubuntu 16.04” (as I had not) then you may not have turned on your firewall. So I could establish an openvpn connection but not get any data back.
I needed to run the following commands:
You can tell if your firewall is enabled by running
Thanks for the great tutorial. I followed the instruction step by step. After that, I can successfully connect to the vpn server. BUT, the speed is extremely slow, i.e. in 20B/s, out 50B/s. Any idea anything I can do to optimize the setup? Many thanks.
In this tutorial, how about using username & password? Because everyone who get the key, can login to the our network vpn. Thanks.
If you want to condense the entire client creation process you can place this script in your home directory [cd ~ && touch mc.sh && chmod +x mc.sh && nano mc.sh]
[hashtag]!/usr/bin/env bash . ./openvpn-ca/vars ./openvpn-ca/build-key ${1} ./client-configs/make_config.sh ${1}
And execute as: ./mc.sh username
Make sure to preserve the exact text or the script might not work [shebang should include “bash” or source command might break]. Replace [hashtag] with # since it’s not rendering in comments.
Thank you for your very instructive guides as always: they’re awesome. I suggest increasing dhparam to 4096 and increasing key size to 4096 in openvpn-ca/vars. Also this tutorial has some tips about ciphers you might wish to implement: https://blog.g3rt.nl/openvpn-security-tips.html. Enabling duplicate-cn might make it easier for users with multiple devices so that they can use only one identity / config file. And lastly, a simple mention about switching to 443/tcp might help many users in getting around restrictive firewalls. Just a few thoughts. Thanks again! :)
On Step 6, I cannot get it to
build-key
. I keep getting this error:DNS is not responding. i have server in digital ocean. when i connect to vpn internet goes off. Hitting the ip works but not the names.
i am not able to access the internet after that. DNS is not responding.
IPv6 VDS VPS NAT /etc/openvpn/server.conf
/etc/ufw/before6.rules
/etc/ufw/sysctl.conf
Hi Justin,
many thanks! It’s the first tuto that I used and can connect my pc to my Pi. Maybe I mist something but on step 13 I get no difference either connected or not. Would you happen to have suggestion for a more exhaustive testing I could do and of course record and or log? What I have in mind is to use the OpenVPN server to connect all members of the family to some kind of private family cloud (maybe OwnCloud). I understand some networks may block this and even my own ISP provider may not allow this. Wow can I find out about all this stuff?
Thanks, Yves
Having problems with Afterwards, we can generate an HMAC signature to strengthen the server’s TLS integrity verification capabilities:
Got this
I followed this OpenVPN setup exactly and it worked perfectly! I tested it by using the OpenVPN Windows client instructions.
That’s great - but I wanted to connect using my Tomato router client.
After a few hours of trial and error - I finally got Tomato configured correctly!
Here are the Tomato OpenVPN Client settings that worked for me:
“BASIC” TAB Interface Type: TUN Protocol: UDP Server Address/Port: xxx.xxx.xxx.xxx Port 1194 (Your Droplet IP) Firewall: Automatic Authorization Mode: TLS Username/Password Authentication: [X] (check) Username: root Password: ••••••••• Username Authen: [ ] (uncheck) Extra HMAC authorization (tls-auth): Outgoing (1) Create NAT on tunnel [X] (check)
“ADVANCED” TAB Poll Interval: 0 Redirect Internet traffic [X] (check) Accept DNS configuration: Disabled Encryption cipher: BF-CBC (Note: AES-128-CBC didn’t work) Compression: Enabled TLS Renegotiation Time: -1 Connection retry: -1 Verify server certificate (tls-remote): [ ] (uncheck)
Custom Configuration: tun-mtu 1500 (type this in the “custom” box)
“KEYS” TAB Copy each key from your client1.ovpn file to the corresponding text box.
That’s it!
When I ran
sudo ufw allow OpenSSH
I got an error message: ERROR: Could not find a profile matching ‘OpenSSH’Another issue I encounter was after I ran
sftp tim@openvpn_server_ip:client-configs/files/client1.ovpn ~/
I received the message ssh: Could not resolve hostname openvpn_server_ip: Name or service not known Couldn’t read packet: Connection reset by peerThanks for any help in advance! I tried running the second command again and it wouldn’t terminate so I had to ctrl + c it myself
This comment has been deleted
Getting a DNS leak after following this. Any fix?
Hi. I have been using that script from road warrior for about a month. It was very easy to set up and get it working the only problem I’m having that its very slow when connected to the vpn? Any Ideas would be great help. Thanks…
Thanks for this, very helpful.
Mine will fail on step 9 - sudo systemctl start openvpn@server
Changing “dh dh1024.pem” to “dh dh2048.pem” in server.conf allows it to start
Does that sound right? Or am I just masking a different problem?
Hello, I am having some issues with copying client1.opvn file over to my mac. Any help, suggestions or if you want me to run some commands please let me know. Thank you
Great tutorial Justin, easy to follow with lots of notes and explanations - superb for linux beginners like myself. Thanks a lot!
I wonder if you could do another tutorial or instruct me on how to configure OpenVPN and Firewall for Multicast? and IGMP? (as I’ve read somewhere) for the Kodi uPNP server to be discoverable by the client connected to the OpenVPN server?
Good Tuto :-) If you want another easy install with docker : https://hub.docker.com/r/sysc0d/openvpn/
Does this setup allow computers connected to the VPN to see each other? I am a little confused on the commonly accepted use of the term VPN, I was always under the impression that a VPN was the equivalent of a LAN over the internet; creating a private network where computers could safely communicate separate of the normal WAN open network. And it was to my understanding that a secure server in which you could connect and traverse the internet “safely” was a proxy. Does OpenVPN make them one in the same or something?
Using something like Hamachi gives the typical usage for a VPN, just a secured private network of systems without external access via the VPN server, but the way you talk about OpenVPN it sounds like you get the best of both worlds? Is that is truly the case, can you also setup OpenVPN to only work as a private network without access to the outside world via the VPN?
OpenVPN is also very good if you, like me, have an SSL cert for one server but don’t want to purchase another but want both web servers to use HTTPS.
I have one web server using apache at my home, which binds to 10.8.0.1:80. Nginx then proxies through 10.8.0.1 for requests from https://pyronexus.com/home/
Like so: pyronexus.com connects to an OpenVPN server on my home network. This VPN server responds only to pyronexus.com’s IP using IPTables. Apache on my home network then binds to 10.8.0.1 Nginx passes all requests from https://pyronexus.com/home/ URI to http://10.8.0.1. Everything else is handled by itself or PHP, etc…
This allows everything sent to the HTTP server on my home network to be encrypted on the OpenVPN tunnel.
Home network: Apache.conf
VHost config
Now, the all HTTP traffic is encrypted on the tunnel :).
Hi, thank you for the excellent tutorial. Unfortunately, I’ve ran into a problem. On all my devices, the openvpn client is stuck at ‘Waiting for server response’ and eventually has a timeout. Can anyone please help me? Thanks!
Hi this guide is awesome. I followed similar guide for 14.04 (from digital ocean tutorials). I am experiencing very slow speeds on this method compared to that one. I’m not sure what is the reason here.
Any idea how that happened ?
Thanks! It’s a great HOWTO
Thank you for the comprehensive guide - I do have an issue that I am hoping someone could help me with though:
On “Step 11: Generate Client Configurations”, when I go to run the new script:
./make_config.sh client1
I am getting the following error:
./make_config.sh: line 9: /home/engineer/client-configs/files/client1.ovpn: No such file or directory
I assumed that this script would generate the file “client1.ovpn” in the files directory, but it seems like it’s looking for this file to already be existing? Further, I tried manually making a blank client1.ovpn file (w/ touch) in the directory and rerunning the script but received the same error.
Does anyone know how to rectify this issue?
Great tutorial. I think the sentence below needs to be corrected.
Your public interface should follow the word “dev”. For example, this result shows the interface named wlp11s0, which is highlighted below:
default via 203.0.113.1 dev eth0 proto static metric 600
Hey, a minor heads up. My configuration only worked when I used my Droplet’s original IP address. I was trying with the Floating IP and/or the host I’d set in the DNS record, and none worked. I wonder if this is an issue with Digital Ocean or if this is the expected behavior.
Cheers!
Anybody has this error after following all the instructions of this and the prerequisite tutorial?
Running as a root and the VPS has TUN/TAP enabled (if that helps in anyways)
Thanks, Sam
How can I use the VPN on one server, where I will have for example 5 users/clients that when logged in can access one host/folder on the server, and other 5 users/clients that will have access to another host/folder without being able to access the host/folder that they don’t have permission to. Is this possible with OpenVPN and how can I achieve that?
When I try to connect from my PC I get an error, Cannot Resolve Host Address: server_IP_address: No such host is known.
Anyone have any suggestions?
When I try to connect on both windows and Android it says the private key is invalid? I didn’t put a password or anything. Any hep?
Hello, Good Day.
I want to disable the server key/cert in the client before it connect in the server. I want to used only the ca.crt to connect to the server.
How configure this setup? thank you in advance.
I fixed my previous problem but now whenever I try to connect it times out?
This is the error I get:
Sun Dec 11 21:31:33 2016 NOTE: --user option is not implemented on Windows Sun Dec 11 21:31:33 2016 NOTE: --group option is not implemented on Windows Sun Dec 11 21:31:33 2016 OpenVPN 2.3.14 x86_64-w64-mingw32 [SSL (OpenSSL)] [LZO] [PKCS11] [IPv6] built on Dec 7 2016 Sun Dec 11 21:31:33 2016 Windows version 6.2 (Windows 8 or greater) 64bit Sun Dec 11 21:31:33 2016 library versions: OpenSSL 1.0.2i 22 Sep 2016, LZO 2.09 Sun Dec 11 21:31:33 2016 MANAGEMENT: TCP Socket listening on [AF_INET]127.0.0.1:25340 Sun Dec 11 21:31:33 2016 Need hold release from management interface, waiting… Sun Dec 11 21:31:34 2016 MANAGEMENT: Client connected from [AF_INET]127.0.0.1:25340 Sun Dec 11 21:31:34 2016 MANAGEMENT: CMD ‘state on’ Sun Dec 11 21:31:34 2016 MANAGEMENT: CMD ‘log all on’ Sun Dec 11 21:31:34 2016 MANAGEMENT: CMD ‘hold off’ Sun Dec 11 21:31:34 2016 MANAGEMENT: CMD ‘hold release’ Sun Dec 11 21:31:34 2016 Control Channel Authentication: tls-auth using INLINE static key file Sun Dec 11 21:31:34 2016 Outgoing Control Channel Authentication: Using 256 bit message hash ‘SHA256’ for HMAC authentication Sun Dec 11 21:31:34 2016 Incoming Control Channel Authentication: Using 256 bit message hash ‘SHA256’ for HMAC authentication Sun Dec 11 21:31:34 2016 Socket Buffers: R=[65536->65536] S=[65536->65536] Sun Dec 11 21:31:34 2016 UDPv4 link local: [undef] Sun Dec 11 21:31:34 2016 UDPv4 link remote: [AF_INET]192.241.137.234:1194 Sun Dec 11 21:31:34 2016 MANAGEMENT: >STATE:1481491894,WAIT, Sun Dec 11 21:32:34 2016 TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity) Sun Dec 11 21:32:34 2016 TLS Error: TLS handshake failed Sun Dec 11 21:32:34 2016 SIGUSR1[soft,tls-error] received, process restarting Sun Dec 11 21:32:34 2016 MANAGEMENT: >STATE:1481491954,RECONNECTING,tls-error, Sun Dec 11 21:32:34 2016 Restart pause, 2 second(s) Sun Dec 11 21:32:36 2016 Socket Buffers: R=[65536->65536] S=[65536->65536] Sun Dec 11 21:32:36 2016 UDPv4 link local: [undef] Sun Dec 11 21:32:36 2016 UDPv4 link remote: [AF_INET]192.241.137.234:1194 Sun Dec 11 21:32:36 2016 MANAGEMENT: >STATE:1481491956,WAIT,
I don’t understand this at all…
All I know is it isn’t working.
Sorry for my bad english. PLEASE HELP ME! I completed all steps. But created file name is client1.ovpn don’t copy to C:/program files/open vpn PuTTY said ‘’ cp: cannot stat ‘client1.ovpn’: No such file or directory ‘’ and it doesn’t copy the file. I writing the code : ls ~/client-configs/files it found the client1.ovpn file but don’t copy to program files. ( I could not finish step 12)
thanks working great from my iphone! 1 question from the vpn server i need http access to other server on the local lan.
so vpn server is on local 10.0.0.10 with public ip etc. and the webserver is on 10.0.0.11:8084
please help:-)
got it simply add push “redirect-gateway def1” to the server.conf
Thanks for making a guide and it is very valuable for me. But, I find some confused followed this guide on a Ubuntu 16.04 system. I write a bash file followed this title and got error at the step 10. Here is the code: { sudo sh -c "cat << EOF > ~/client-configs/make_config.sh #!/bin/bash
First argument: Client identifier
KEY_DIR=~/openvpn-ca/keys OUTPUT_DIR=~/client-configs/files BASE_CONFIG=~/client-configs/base.conf
cat ${BASE_CONFIG}
<(echo -e ‘<ca>’)
${KEY_DIR}/ca.crt
<(echo -e ‘</ca>\n<cert>’)
${KEY_DIR}/${1}.crt
<(echo -e ‘</cert>\n<key>’)
${KEY_DIR}/${1}.key
<(echo -e ‘</key>\n<tls-auth>’)
${KEY_DIR}/ta.key
<(echo -e ‘</tls-auth>’)
> ${OUTPUT_DIR}/${1}.ovpn EOF" }
But, the Ubuntu returned: cat: /home//openvpn-ca/keys/.crt: No such file or directory cat: /home//openvpn-ca/keys/.key: No such file or directory
How do I solve the problem? Thanks!!
Hi, I don’t understand this:
where is the file “ta.key” ? Thanks!
i checked many times on this setup. there are no dns leaking.
Really nice tutorial, thank you. Everything worked right away, except for client to client communication. I cannot ping other clients connected to the server through their virtual address. I tried enabling the “client-to-client” option in the server configuration, but this had no effect. How should I configure the server such that clients may communicate with each other through their virtual adresses?
Hi, Great guide, very comprehensive and very much appreciated. Although as a novice, I have an issue that I hope someone can help with. In Section 8: Identifying the public network interface of our machine*
When I run the command ip route | grep default I get the following results which dont look right according to the guide.
default via 138.197.32.1 dev eth0 onlink
Can someone please point me in the right direction on how to obtain the public network interface name.
PS, I have followed this and the prerequisite tutorial, everything has been working fine up-to this point. Regards
Will this work in China? I am totally new to VPN and I use Ubunt 16.04. Basically I’d like to continue enjoying facebook and all the banned sites in China.
Cheers