Tutorial

How To Set Up an OpenVPN Server on Ubuntu 18.04

Updated on September 28, 2021

Manager, Developer Education

English
How To Set Up an OpenVPN Server on Ubuntu 18.04
Not using Ubuntu 18.04?Choose a different version or distribution.
Ubuntu 18.04

A previous version of this tutorial was written by Justin Ellingwood

Introduction

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 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, you will set up an OpenVPN server on an Ubuntu 18.04 server and then configure access to it from Windows, macOS, iOS and/or Android. This tutorial will keep the installation and configuration steps as simple as possible for each of 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.

Prerequisites

To complete this tutorial, you will need access to an Ubuntu 18.04 server to host your OpenVPN service. You will need to configure a non-root user with sudo privileges before you start this guide. You can follow our Ubuntu 18.04 initial server setup guide to set up a user with appropriate permissions. The linked tutorial will also set up a firewall, which is assumed to be in place throughout this guide.

Additionally, you will need a separate machine to serve as your certificate authority (CA). While it’s technically possible to use your OpenVPN server or your local machine as your CA, this is not recommended as it opens up your VPN to some security vulnerabilities. Per OpenVPN’s Getting started How-To tutorial, you should place your CA on a standalone machine that’s dedicated to importing and signing certificate requests. For this reason, this guide assumes that your CA is on a separate Ubuntu 18.04 server that also has a non-root user with sudo privileges and a basic firewall.

Please note that if you disable password authentication while configuring these servers, you may run into difficulties when transferring files between them later on in this guide. To resolve this issue, you could re-enable password authentication on each server. Alternatively, you could generate an SSH keypair for each server, then add the OpenVPN server’s public SSH key to the CA machine’s authorized_keys file and vice versa. See How to Set Up SSH Keys on Ubuntu 18.04 for instructions on how to perform either of these solutions.

When you have these prerequisites in place, you can move on to Step 1 of this tutorial.

Step 1 — Installing OpenVPN and EasyRSA

To start off, update your VPN server’s package index and install OpenVPN. OpenVPN is available in Ubuntu’s default repositories, so you can use apt for the installation:

  1. sudo apt update
  2. sudo apt install openvpn

OpenVPN is a TLS/SSL VPN. This means that it utilizes certificates in order to encrypt traffic between the server and clients. To issue trusted certificates, you will set up your own simple certificate authority (CA). To do this, we will download the latest version of EasyRSA, which we will use to build our CA public key infrastructure (PKI), from the project’s official GitHub repository.

As mentioned in the prerequisites, we will build the CA on a standalone server. The reason for this approach is that, if an attacker were able to infiltrate your server, they would be able to access your CA private key and use it to sign new certificates, giving them access to your VPN. Accordingly, managing the CA from a standalone machine helps to prevent unauthorized users from accessing your VPN. Note, as well, that it’s recommended that you keep the CA server turned off when not being used to sign keys as a further precautionary measure.

To begin building the CA and PKI infrastructure, use wget to download the latest version of EasyRSA on both your CA machine and your OpenVPN server. To get the latest version, go to the Releases page on the official EasyRSA GitHub project, copy the download link for the file ending in .tgz, and then paste it into the following command:

  1. wget -P ~/ https://github.com/OpenVPN/easy-rsa/releases/download/v3.0.8/EasyRSA-3.0.8.tgz

Then extract the tarball:

  1. cd ~
  2. tar xvf EasyRSA-3.0.8.tgz

You have successfully installed all the required software on your server and CA machine. Continue on to configure the variables used by EasyRSA and to set up a CA directory, from which you will generate the keys and certificates needed for your server and clients to access the VPN.

Step 2 — Configuring the EasyRSA Variables and Building the CA

EasyRSA comes installed with a configuration file which you can edit to define a number of variables for your CA.

On your CA machine, navigate to the EasyRSA directory:

  1. cd ~/EasyRSA-3.0.8/

Inside this directory is a file named vars.example. Make a copy of this file, and name the copy vars without a file extension:

  1. cp vars.example vars

Open this new file using your preferred text editor. Here, we’ll use nano:

  1. nano vars

Find the settings that set field defaults for new certificates. It will look something like this:

~/EasyRSA-3.0.8/vars
. . .

#set_var EASYRSA_REQ_COUNTRY    "US"
#set_var EASYRSA_REQ_PROVINCE   "California"
#set_var EASYRSA_REQ_CITY       "San Francisco"
#set_var EASYRSA_REQ_ORG        "Copyleft Certificate Co"
#set_var EASYRSA_REQ_EMAIL      "me@example.net"
#set_var EASYRSA_REQ_OU         "My Organizational Unit"

. . .

Uncomment these lines by removing the pound sign (#) at the beginning of each one. Then update the highlighted values to whatever you’d prefer, but do not leave them blank:

~/EasyRSA-3.0.8/vars
. . .

set_var EASYRSA_REQ_COUNTRY    "US"
set_var EASYRSA_REQ_PROVINCE   "New York"
set_var EASYRSA_REQ_CITY       "New York City"
set_var EASYRSA_REQ_ORG        "DigitalOcean"
set_var EASYRSA_REQ_EMAIL      "admin@example.com"
set_var EASYRSA_REQ_OU         "Community"

. . .

When you are finished, save and close the file. If you edited the file using nano, do so by pressing CTRL + X, Y, and then ENTER.

Within the EasyRSA directory is a script called easyrsa which is called to perform a variety of tasks involved with building and managing the CA. Run this script with the init-pki option to initiate the public key infrastructure on the CA server:

  1. ./easyrsa init-pki
Output
. . . init-pki complete; you may now create a CA or requests. Your newly created PKI dir is: /home/sammy/EasyRSA-3.0.8/pki

After this, call the easyrsa script again, following it with the build-ca option. This will build the CA and create two important files — ca.crt and ca.key — which make up the public and private sides of an SSL certificate.

  • ca.crt is the CA’s public certificate file which, in the context of OpenVPN, the server and the client use to inform one another that they are part of the same web of trust and not someone performing a man-in-the-middle attack. For this reason, your server and all of your clients will need a copy of the ca.crt file.
  • ca.key is the private key which the CA machine uses to sign keys and certificates for servers and clients. If an attacker gains access to your CA and, in turn, your ca.key file, they will be able to sign certificate requests and gain access to your VPN, impeding its security. This is why your ca.key file should only be on your CA machine and that, ideally, your CA machine should be kept offline when not signing certificate requests as an extra security measure.

If you don’t want to be prompted for a password every time you interact with your CA, you can run the build-ca command with the nopass option, like this:

  1. ./easyrsa build-ca nopass

In the output, you’ll be asked to confirm the common name for your CA:

Output
. . . Common Name (eg: your user, host, or server name) [Easy-RSA CA]:

The common name is the name used to refer to this machine in the context of the certificate authority. You can enter any string of characters for the CA’s common name but, for simplicity’s sake, press ENTER to accept the default name.

With that, your CA is in place and it’s ready to start signing certificate requests.

Step 3 — Creating the Server Certificate, Key, and Encryption Files

Now that you have a CA ready to go, you can generate a private key and certificate request from your server and then transfer the request over to your CA to be signed, creating the required certificate. You’re also free to create some additional files used during the encryption process.

Start by navigating to the EasyRSA directory on your OpenVPN server:

  1. cd EasyRSA-3.0.8/

From there, run the easyrsa script with the init-pki option. Although you already ran this command on the CA machine, it’s necessary to run it here because your server and CA will have separate PKI directories:

  1. ./easyrsa init-pki

Then call the easyrsa script again, this time with the gen-req option followed by a common name for the machine. Again, this could be anything you like but it can be helpful to make it something descriptive. Throughout this tutorial, the OpenVPN server’s common name will simply be “server”. Be sure to include the nopass option as well. Failing to do so will password-protect the request file which could lead to permissions issues later on:

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 directory, 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.

  1. ./easyrsa gen-req server nopass

This will create a private key for the server and a certificate request file called server.req. Copy the server key to the /etc/openvpn/ directory:

  1. sudo cp ~/EasyRSA-3.0.8/pki/private/server.key /etc/openvpn/

Using a secure method (like SCP, in our example below), transfer the server.req file to your CA machine:

  1. scp ~/EasyRSA-3.0.8/pki/reqs/server.req sammy@your_CA_ip:/tmp

Next, on your CA machine, navigate to the EasyRSA directory:

  1. cd EasyRSA-3.0.8/

Using the easyrsa script again, import the server.req file, following the file path with its common name:

  1. ./easyrsa import-req /tmp/server.req server

Then sign the request by running the easyrsa script with the sign-req option, followed by the request type and the common name. The request type can either be client or server, so for the OpenVPN server’s certificate request, be sure to use the server request type:

  1. ./easyrsa sign-req server server

In the output, you’ll be asked to verify that the request comes from a trusted source. Type yes then press ENTER to confirm this:

You are about to sign the following certificate.
Please check over the details shown below for accuracy. Note that this request
has not been cryptographically verified. Please be sure it came from a trusted
source or that you have verified the request checksum with the sender.

Request subject, to be signed as a server certificate for 3650 days:

subject=
    commonName                = server


Type the word 'yes' to continue, or any other input to abort.
  Confirm request details: yes

If you encrypted your CA key, you’ll be prompted for your password at this point.

Next, transfer the signed certificate back to your VPN server using a secure method:

  1. scp pki/issued/server.crt sammy@your_server_ip:/tmp

Before logging out of your CA machine, transfer the ca.crt file to your server as well:

  1. scp pki/ca.crt sammy@your_server_ip:/tmp

Next, log back into your OpenVPN server and copy the server.crt and ca.crt files into your /etc/openvpn/ directory:

  1. sudo cp /tmp/{server.crt,ca.crt} /etc/openvpn/

Then navigate to your EasyRSA directory:

  1. cd EasyRSA-3.0.8/

From there, create a strong Diffie-Hellman key to use during key exchange by typing:

  1. ./easyrsa gen-dh

This may take a few minutes to complete. Once it does, generate an HMAC signature to strengthen the server’s TLS integrity verification capabilities:

  1. openvpn --genkey --secret ta.key

When the command finishes, copy the two new files to your /etc/openvpn/ directory:

  1. sudo cp ~/EasyRSA-3.0.8/ta.key /etc/openvpn/
  2. sudo cp ~/EasyRSA-3.0.8/pki/dh.pem /etc/openvpn/

With that, all the certificate and key files needed by your server have been generated. You’re ready to create the corresponding certificates and keys which your client machine will use to access your OpenVPN server.

Step 4 — Generating a Client Certificate and Key Pair

Although you can generate a private key and certificate request on your client machine and then send it to the CA to be signed, this guide outlines a process for generating the certificate request on the server. The benefit of this is that we can create a script which will automatically generate client configuration files that contain all of the required keys and certificates. This lets you avoid having to transfer keys, certificates, and configuration files to clients and streamlines the process of joining the VPN.

We will generate a single client key and certificate pair for this guide. If you have more than one client, you can repeat this process for each one. Please note, though, that you will need to pass a unique name value to the script for every client. Throughout this tutorial, the first certificate/key pair is referred to as client1.

Get started by creating a directory structure within your home directory to store the client certificate and key files:

  1. mkdir -p ~/client-configs/keys

Since you will store your clients’ certificate/key pairs and configuration files in this directory, you should lock down its permissions now as a security measure:

  1. chmod -R 700 ~/client-configs

Next, navigate back to the EasyRSA directory and run the easyrsa script with the gen-req and nopass options, along with the common name for the client:

  1. cd ~/EasyRSA-3.0.8/
  2. ./easyrsa gen-req client1 nopass

Press ENTER to confirm the common name. Then, copy the client1.key file to the /client-configs/keys/ directory you created earlier:

  1. cp pki/private/client1.key ~/client-configs/keys/

Next, transfer the client1.req file to your CA machine using a secure method:

  1. scp pki/reqs/client1.req sammy@your_CA_ip:/tmp

On your CA machine, navigate to the EasyRSA directory, and import the certificate request:

  1. cd EasyRSA-3.0.8/
  2. ./easyrsa import-req /tmp/client1.req client1

Then sign the request as you did for the server in the previous step. This time, though, be sure to specify the client request type:

  1. ./easyrsa sign-req client client1

At the prompt, enter yes to confirm that you intend to sign the certificate request and that it came from a trusted source:

Output
Type the word 'yes' to continue, or any other input to abort. Confirm request details: yes

Again, if you encrypted your CA key, you’ll be prompted for your password here.

This will create a client certificate file named client1.crt. Transfer this file back to the server:

  1. scp pki/issued/client1.crt sammy@your_server_ip:/tmp

SSH back into your OpenVPN server and copy the client certificate to the /client-configs/keys/ directory:

  1. cp /tmp/client1.crt ~/client-configs/keys/

Next, copy the ca.crt and ta.key files to the /client-configs/keys/ directory as well:

  1. cp ~/EasyRSA-3.0.8/ta.key ~/client-configs/keys/
  2. sudo cp /etc/openvpn/ca.crt ~/client-configs/keys/

With that, your server and client’s certificates and keys have all been generated and are stored in the appropriate directories on your server. There are still a few actions that need to be performed with these files, but those will come in a later step. For now, you can move on to configuring OpenVPN on your server.

Step 5 — Configuring the OpenVPN Service

Now that both your client and server’s certificates and keys have been generated, you can begin configuring the OpenVPN service to use these credentials.

Start by copying a sample OpenVPN configuration file into the configuration directory and then extract it in order to use it as a basis for your setup:

  1. sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
  2. sudo gzip -d /etc/openvpn/server.conf.gz

Open the server configuration file in your preferred text editor:

  1. sudo nano /etc/openvpn/server.conf

Find the HMAC section by looking for the tls-auth directive. This line should already be uncommented, but if isn’t then remove the “;” to uncomment it:

/etc/openvpn/server.conf
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-256-CBC cipher offers a good level of encryption and is well supported. Again, this line should already be uncommented, but if it isn’t then just remove the “;” preceding it:

/etc/openvpn/server.conf
cipher AES-256-CBC

Below this, add an auth directive to select the HMAC message digest algorithm. For this, SHA256 is a good choice:

/etc/openvpn/server.conf
auth SHA256

Next, find the line containing a dh directive which defines the Diffie-Hellman parameters. Because of some recent changes made to EasyRSA, the filename for the Diffie-Hellman key may be different than what is listed in the example server configuration file. If necessary, change the file name listed here by removing the 2048 so it aligns with the key you generated in the previous step:

/etc/openvpn/server.conf
dh dh.pem

Finally, find the user and group settings and remove the “;” at the beginning of each to uncomment these lines:

/etc/openvpn/server.conf
user nobody
group nogroup

The changes you’ve made to the sample server.conf file up to this point are necessary in order for OpenVPN to function. The changes outlined below are optional, though they too are needed for many common use cases.

(Optional) Push DNS Changes to Redirect All Traffic Through the VPN

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.

There are a few directives in the server.conf file which you must change in order to enable this functionality. Find the redirect-gateway section and remove the semicolon “;” from the beginning of the redirect-gateway line to uncomment it:

/etc/openvpn/server.conf
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:

/etc/openvpn/server.conf
push "dhcp-option DNS 208.67.222.222"
push "dhcp-option DNS 208.67.220.220"

This will assist clients in reconfiguring their DNS settings to use the VPN tunnel for as the default gateway.

(Optional) Adjust the Port and Protocol

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 on your OpenVPN server, port 443 is a popular choice since it is usually allowed through firewall rules.

/etc/openvpn/server.conf
# Optional!
port 443

Oftentimes, the protocol is restricted to that port as well. If so, change proto from UDP to TCP:

/etc/openvpn/server.conf
# Optional!
proto tcp

If you do switch the protocol to TCP, you will need to change the explicit-exit-notify directive’s value from 1 to 0, as this directive is only used by UDP. Failing to do so while using TCP will cause errors when you start the OpenVPN service:

/etc/openvpn/server.conf
# Optional!
explicit-exit-notify 0

If you have no need to use a different port and protocol, it is best to leave these two settings as their defaults.

(Optional) Point to Non-Default Credentials

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 name, “server”, this is already set correctly:

/etc/openvpn/server.conf
cert server.crt
key server.key

When you are finished, save and close the file.

After going through and making whatever changes to your server’s OpenVPN configuration are required for your specific use case, you can begin making some changes to your server’s networking.

Step 6 — Adjusting the Server Networking Configuration

There are some aspects of the server’s networking configuration that need to be tweaked so that OpenVPN can correctly route traffic through the VPN. The first of these is IP forwarding, a method for determining where IP traffic should be routed. This is essential to the VPN functionality that your server will provide.

Adjust your server’s default IP forwarding setting by modifying the /etc/sysctl.conf file:

  1. sudo nano /etc/sysctl.conf

Inside, look for the commented line that sets net.ipv4.ip_forward. Remove the “#” character from the beginning of the line to uncomment this setting:

/etc/sysctl.conf
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:

  1. sudo sysctl -p
Output
net.ipv4.ip_forward = 1

If you followed the Ubuntu 18.04 initial server setup guide listed in the prerequisites, you should have a UFW firewall in place. Regardless of whether you use the firewall to block unwanted traffic (which you almost always should do), for this guide you need a firewall to manipulate some of the traffic coming into the server. Some of the firewall rules must be modified to enable masquerading, an iptables concept that provides on-the-fly dynamic network address translation (NAT) to correctly route client connections.

Before opening the firewall configuration file to add the masquerading rules, you must first find the public network interface of your machine. To do this, type:

  1. ip route | grep default

Your public interface is the string found within this command’s output that follows the word “dev”. For example, this result shows the interface named eth0, which is highlighted below:

Output
default via 203.0.113.1 dev eth0 proto static

When you have the interface associated with your default route, open the /etc/ufw/before.rules file to add the relevant configuration:

  1. sudo nano /etc/ufw/before.rules

UFW rules are typically added using the ufw command. Rules listed in the before.rules file, though, are read and 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. Remember to replace eth0 in the -A POSTROUTING line below with the interface you found in the above command:

/etc/ufw/before.rules
#
# 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 eth0 (change to the interface you discovered!)
-A POSTROUTING -s 10.8.0.0/8 -o eth0 -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.

Next, you need to tell UFW to allow forwarded packets by default as well. To do this, open the /etc/default/ufw file:

  1. sudo nano /etc/default/ufw

Inside, find the DEFAULT_FORWARD_POLICY directive and change the value from DROP to ACCEPT:

/etc/default/ufw
DEFAULT_FORWARD_POLICY="ACCEPT"

Save and close the file when you are finished.

Next, 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.

In case you forgot to add the SSH port when following the prerequisite tutorial, add it here as well:

  1. sudo ufw allow 1194/udp
  2. sudo ufw allow OpenSSH

After adding those rules, disable and re-enable UFW to restart it and load the changes from all of the files you’ve modified:

  1. sudo ufw disable
  2. sudo ufw enable

Your server is now configured to correctly handle OpenVPN traffic.

Step 7 — Starting and Enabling the OpenVPN Service

You’re finally ready to start the OpenVPN service on your server. This is done using the systemd utility systemctl.

Start the OpenVPN server by specifying your configuration file name as an instance variable after the systemd unit file name. The configuration file for your server is called /etc/openvpn/server.conf, so add @server to end of your unit file when calling it:

  1. sudo systemctl start openvpn@server

Double-check that the service has started successfully by typing:

  1. sudo systemctl status openvpn@server

If everything went well, your output will look something 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

You can also check that the OpenVPN tun0 interface is available by typing:

  1. ip addr show tun0

This will output a configured interface:

Output
4: 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

After starting the service, enable it so that it starts automatically at boot:

  1. sudo systemctl enable openvpn@server

Your OpenVPN service is now up and running. Before you can start using it, though, you must first create a configuration file for the client machine. This tutorial already went over how to create certificate/key pairs for clients, and in the next step we will demonstrate how to create an infrastructure that will generate client configuration files easily.

Step 8 — Creating the Client Configuration Infrastructure

Creating configuration files for OpenVPN clients can be somewhat involved, as every client must have its own config and each must align with the settings outlined in the server’s configuration file. Rather than writing a single configuration file that can only be used on one client, this step outlines a process for building a client configuration infrastructure which you can use to generate config files on-the-fly. You will first create a “base” configuration file then build a script which will allow you to generate unique client config files, certificates, and keys as needed.

Get started by creating a new directory where you will store client configuration files within the client-configs directory you created earlier:

  1. mkdir -p ~/client-configs/files

Next, copy an example client configuration file into the client-configs directory to use as your base configuration:

  1. cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf ~/client-configs/base.conf

Open this new file in your text editor:

  1. nano ~/client-configs/base.conf

Inside, locate the remote directive. This points the client to your OpenVPN server address — the public IP address of your OpenVPN server. If you decided to change the port that the OpenVPN server is listening on, you will also need to change 1194 to the port you selected:

~/client-configs/base.conf
. . .
# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote your_server_ip 1194
. . .

Be sure that the protocol matches the value you are using in the server configuration:

~/client-configs/base.conf
proto udp

Next, uncomment the user and group directives by removing the “;” at the beginning of each line:

~/client-configs/base.conf
# 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 you will add the certs and keys within the file itself shortly:

~/client-configs/base.conf
# 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

Similarly, comment out the tls-auth directive, as you will add ta.key directly into the client configuration file:

~/client-configs/base.conf
# If a tls-auth key is used on the server
# then every client must also have the key.
#tls-auth ta.key 1

Mirror the cipher and auth settings that you set in the /etc/openvpn/server.conf file:

~/client-configs/base.conf
cipher AES-256-CBC
auth SHA256

Next, add the key-direction directive somewhere in the file. You must set this to “1” for the VPN to function correctly on the client machine:

~/client-configs/base.conf
key-direction 1

Finally, add a few commented out lines to handle various methods that Linux based VPN clients will use for DNS resolution. You’ll add two similar, but separate sets of commented out lines. The first set is for clients that do not use systemd-resolved to manage DNS. These clients rely on the resolvconf utility to update DNS information for Linux clients.

~/client-configs/base.conf
; script-security 2
; up /etc/openvpn/update-resolv-conf
; down /etc/openvpn/update-resolv-conf

Now add another set of lines for clients that use systemd-resolved for DNS resolution:

~/client-configs/base.conf
; script-security 2
; up /etc/openvpn/update-systemd-resolved
; down /etc/openvpn/update-systemd-resolved
; down-pre
; dhcp-option DOMAIN-ROUTE .

Save and close the file when you are finished.

Later in Step 10 - Installing the Client Configuration step of this tutorial you will learn how to determine how DNS resolution works on Linux clients and which section to uncomment.

Next, create a simple script that will compile your base configuration with the relevant certificate, key, and encryption files and then place the generated configuration in the ~/client-configs/files directory. Open a new file called make_config.sh within the ~/client-configs directory:

  1. nano ~/client-configs/make_config.sh

Inside, add the following content:

~/client-configs/make_config.sh
#!/bin/bash

# First argument: Client identifier

KEY_DIR=~/client-configs/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

Save and close the file when you are finished.

Before moving on, be sure to mark this file as executable by typing:

  1. chmod 700 ~/client-configs/make_config.sh

This script will make a copy of the base.conf file you made, collect all the certificate and key files you’ve created for your client, extract their contents, append them to the copy of the base configuration file, and export all of this content into a new client configuration file. This means that, rather than having to manage the client’s configuration, certificate, and key files separately, all the required information is stored in one place. The benefit of this is that if you ever need to add a client in the future, you can just run this script to quickly create the config file and ensure that all the important information is stored in a single, easy-to-access location.

Please note that any time you add a new client, you will need to generate new keys and certificates for it before you can run this script and generate its configuration file. You will get some practice using this script in the next step.

Step 9 — Generating Client Configurations

If you followed along with this guide, you created a client certificate and key named client1.crt and client1.key, respectively, in Step 4. You can generate a config file for these credentials by moving into your ~/client-configs directory and running the script you made at the end of the previous step:

  1. cd ~/client-configs
  2. sudo ./make_config.sh client1

This will create a file named client1.ovpn in your ~/client-configs/files directory:

  1. ls ~/client-configs/files
Output
client1.ovpn

You need to transfer this file to the device you plan to use as the client. 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 device’s operating system and your personal preferences, a dependable and secure method is 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 the client1.ovpn example which you can run from your local computer (macOS or Linux). It places the .ovpn file in your home directory:

  1. sftp sammy@your_server_ip:client-configs/files/client1.ovpn ~/

Here are several tools and tutorials for securely transferring files from the server to a local computer:

Step 10 — Installing the Client Configuration

This section covers how to install a client VPN profile on Windows, macOS, Linux, iOS, and Android. None of these client instructions are dependent on one another, so feel free to skip to whichever is applicable to your device.

The OpenVPN connection will have the same name as whatever you called the .ovpn file. In regards to this tutorial, this means that the connection is named client1.ovpn, aligning with the first client file you generated.

Windows

Installing

Download the OpenVPN client application for Windows from 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 make it available.

You must run OpenVPN 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 must preset this 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 you can connect and disconnect the VPN 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 your 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.

macOS

Installing

Tunnelblick is a free, open source OpenVPN client for macOS. 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. Answer I have configuration files 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 the Tunnelblick icon 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 client1 menu item to initiate the VPN connection.

Linux

Installing

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:

  1. sudo apt update
  2. sudo apt install openvpn

On CentOS you can enable the EPEL repositories and then install it by typing:

  1. sudo yum install epel-release
  2. sudo yum install openvpn

Configuring Clients that use systemd-resolved

First determine if your system is using systemd-resolved to handle DNS resolution by checking the /etc/resolv.conf file:

  1. cat /etc/resolv.conf
Output
# This file is managed by man:systemd-resolved(8). Do not edit. . . . nameserver 127.0.0.53 options edns0

If your system is configured to use systemd-resolved for DNS resolution, the IP address after the nameserver option will be 127.0.0.53. There should also be comments in the file like the output that is shown that explain how systemd-resolved is managing the file. If you have a different IP address than 127.0.0.53 then chances are your system is not using systemd-resolved and you can go to the next section on configuring Linux clients that have an update-resolv-conf script instead.

To support these clients, first install the openvpn-systemd-resolved package. It provides scripts that will force systemd-resolved to use the VPN server for DNS resolution.

  1. sudo apt install openvpn-systemd-resolved

One that package is installed, configure the client to use it, and to send all DNS queries over the VPN interface. Open the client’s VPN file:

  1. nano client1.ovpn

Now uncomment the following lines that you added earlier:

client1.ovpn
script-security 2
up /etc/openvpn/update-systemd-resolved
down /etc/openvpn/update-systemd-resolved
down-pre
dhcp-option DOMAIN-ROUTE .

Save and close the file after uncommenting these lines

Configuring Clients that use update-resolv-conf

If your system is not using systemd-resolved to manage DNS, check to see if your distribution includes an /etc/openvpn/update-resolv-conf script instead:

  1. ls /etc/openvpn
Output
update-resolv-conf

If your client includes the update-resolv-conf file, then edit the OpenVPN client configuration file that you transferred earlier:

  1. nano client1.ovpn

Uncomment the three lines you added to adjust the DNS settings:

client1.ovpn
script-security 2
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf

If you are using CentOS, change the group directive from nogroup to nobody to match the distribution’s available groups:

client1.ovpn
group nobody

Save and close the file.

Connecting your Client Machine to the VPN

Now, you can connect to the VPN by just pointing the openvpn command to the client configuration file:

  1. sudo openvpn --config client1.ovpn

This should connect you to your VPN.

iOS

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.

The process of completing the transfer with iTunes is 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.

iTunes showing the VPN profile ready to load on the iPhone

Now launch the OpenVPN app on the iPhone. You will receive a notification that a new profile is ready to import. Tap the green plus sign to import it.

The OpenVPN iOS app showing new profile ready to import

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.

The OpenVPN iOS app connected to the VPN

Android

Installing

Open the Google Play Store. Search for and install Android OpenVPN Connect, the official Android OpenVPN client application.

You can transfer the .ovpn profile 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.

The OpenVPN Android app profile import menu selection

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.

The OpenVPN Android app selecting VPN profile to import

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.

The OpenVPN Android app ready to connect to the VPN

Step 11 — Testing Your VPN Connection (Optional)

Note: This method for testing your VPN connection will only work if you opted to route all your traffic through the VPN in Step 5.

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. A completely different IP address (that of your VPN server) should now appear, and this is 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.

Step 12 — Revoking Client Certificates

Occasionally, you may need to revoke a client certificate to prevent further access to the OpenVPN server.

To do so, navigate to the EasyRSA directory on your CA machine:

  1. cd EasyRSA-3.0.8/

Next, run the easyrsa script with the revoke option, followed by the client name you wish to revoke:

  1. ./easyrsa revoke client2

This will ask you to confirm the revocation by entering yes:

Output
Please confirm you wish to revoke the certificate with the following subject: subject= commonName = client2 Type the word 'yes' to continue, or any other input to abort. Continue with revocation: yes

After confirming the action, the CA will fully revoke the client’s certificate. However, your OpenVPN server currently has no way to check whether any clients’ certificates have been revoked and the client will still have access to the VPN. To correct this, create a certificate revocation list (CRL) on your CA machine:

  1. ./easyrsa gen-crl

This will generate a file called crl.pem. Securely transfer this file to your OpenVPN server:

  1. scp ~/EasyRSA-3.0.8/pki/crl.pem sammy@your_server_ip:/tmp

On your OpenVPN server, copy this file into your /etc/openvpn/ directory:

  1. sudo cp /tmp/crl.pem /etc/openvpn

Next, open the OpenVPN server configuration file:

  1. sudo nano /etc/openvpn/server.conf

At the bottom of the file, add the crl-verify option, which will instruct the OpenVPN server to check the certificate revocation list that we’ve created each time a connection attempt is made:

/etc/openvpn/server.conf
crl-verify crl.pem

Save and close the file.

Finally, restart OpenVPN to implement the certificate revocation:

  1. sudo systemctl restart openvpn@server

The client should no longer be able to successfully connect to the server using the old credential.

To revoke additional clients, follow this process:

  1. Revoke the certificate with the ./easyrsa revoke client_name command
  2. Generate a new CRL
  3. Transfer the new crl.pem file to your OpenVPN server and copy it to the /etc/openvpn directory to overwrite the old list.
  4. Restart the OpenVPN service.

You can use this process to revoke any certificates that you’ve previously issued for your server.

Conclusion

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 4 and 9-11 for each additional device. To revoke access to clients, just follow step 12.

Get an OpenVPN Access Server in seconds with our DigitalOcean OpenVPN Access Server 1-click!

Learn more here

About the authors
Default avatar

Manager, Developer Education

Technical Writer @ DigitalOcean

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
115 Comments
Leave a comment...

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!

As always, an excellent tutorial. One question: Don’t we also need to comment out the line “tls-auth ta.key 1” in ~/client-configs/base.conf? I was running into errors with the config files generated by make_config.sh, possibly because the config file was pointing the OpenVPN client to a file that didn’t exist (but which was referenced inline).

Separately, would it be better to use tls-crypt instead of tls-auth, given what I understand is an additional layer of security for tls-crypt? (Caveat: I’m not a pro, just saw -crypt mentioned when I was looking for a solution to the issue noted above).

@khakist if you comment the line “tls-auth ta.key 1”, then you’d have to keep the key on the folder you’re running OpenVPN from the client side. The tutorial shows that you actually don’t need that key on the client, that’s why it is uncommented.

Also, keep in mind that if you try to run your OpenVPN client from outside your personal area, the network might be filtered and prevent TLS handhsake to work properly (test on a personal hotspot if you’re at school/work).

I think I was having the same issue. I followed the tutorial and I checked that my ~/client-configs/base.conf did not have tls-auth ta.key 1 commented, I kept getting an error saying the following when I tried to import the .ovpn to tunnelblick (mac OS):

At line 108 of the OpenVPN configuration file: The configuration file refers to a file

ta.key

which should be located at

/Users/myname/ta.key

but the file does not exist.

I just went to line 108 and commented it out and I was able to connect to the VPN fine. I then edited the ~/client-configs/base.conf, commented the tls-auth ta.key 1 line, re-ran the make_config.sh script and it commented out line 108 right away so it wasn’t asking me to have the ta.key on the client machine.

I had the same issue while importing the .ovpn to iOS & MacOS. On iOS, I was getting the error Error loading profile. Missing/bad file : ta.key : cannot open for read: /var/mobile/Containers/Data/Application/[…] I solved it by commenting the line tls-auth ta.key 1 in the ovpn file.

Thanks for the great tutorial.

Consider using CloudFlare nameservers instead of OpenDNS for dhcp-option. Their IPs are 1.1.1.1 and 1.0.0.1. CF is really faster.

Good article.

Hi, I just wanted to say, it’s a very good tutorial. Nevertheless, in my opinion the name “server” could cause some confusion. So e.g. if we use the command ./easyrsa gen-req server nopass, and then we have names like server.conf or server.req. Does that mean then that if my server name was myserver, that we would have myserver.conf and myserver.req like in the command ./easyrsa gen-req myserver nopass? I do suppose that it is called server.conf and may be also server.req but it’s not unique. And this is a tutorial for people who don’t know much… Thanks

Hi! I see you have mentioned a requirement for a second machine to issue CA certificates, but I’m not certain this required practice with openVPN. Following the link to the official documentation, I don’t see much mention of it? From my (very limited) knowledge of crypto, I guess this is to prevent MITM attacks? If so, does this server require the same kind of uptime as the main openVPN server? What instance is the CA server actually needed, beyond the private-public key exchange to establish trust? I read on the openVPN website, “Place your CA files on a storage which can be offline as much as possible, only to be activated when you need to get a new certificate for a client or server.”

Sorry for the probably basic question, this part is not my area of expertise. Thanks.

Mark Drake
DigitalOcean Employee
DigitalOcean Employee badge
June 28, 2018

Hello @snapdragon20 , and thank you for your question!

You’re correct in your thinking that the purpose of using a second machine to issue CA certificates is to help prevent MITM attacks. I believe that quote you mention is referring specifically to the ca.key file, which is the file used to create and sign certificates. If a malicious actor were to get a hold of your ca.key file, they would be able to issue certificates and gain access to your VPN. This is why it’s recommended that you either turn off the CA server or otherwise disconnect it from the internet when you’re not using it to issue or revoke certificates.

We chose the method for creating an OpenVPN server described in this tutorial to help make the process simple while also keeping the importance of security in mind. While it is technically possible to issue CA certificates directly from your OpenVPN server, this would make it significantly easier for someone to gain access to your certificate authority and is therefore not as secure as issuing certs from a second machine that’s kept offline as much as possible.

Thank you @mdrake for an excellent article. It’s good decision to have CA on different machine. I’ve got a question - is there some way to simplify adding new clients and generating their ovpn profiles? The question rises because, if I, for example, want to generate 30-40 ovpn profiles - it will be a lot of back and forth between 2 servers. Is there a way to simplify this? I was looking into OpenVPN Access Server, but as I understand it configures the CA to be on the same server as the openvpn server.

Could you move the ca.key file to a USB drive and unplug it?

I apologize for an elementary question: if one chooses to have the second machine to issue the CA certificates be on DigitalOcean, does that require a second droplet?

First of all, thank you for an awesome and extensive guide!

Everything seems to be working as intended, but I run into an issue when I try to connect to the VPN-server. I only have a Windows client to test with and I have dumped the ovpn-file created on the VPN-server to my client. When I try to connect, I get this error:

Options error: Unrecognized option or missing or extra parameter(s) in file.ovpn:133: —BEGIN (2.4.6)

This line in the ovpn-file is obviously the line that says “--------begin certificate--------”

Does anyone have any idea what I can do to fix this?

Nevermind, for some reason the <ca> in the beginning of the certificate were gone. I added it and everything seems to be working as intended now.

I’ve been running my OVPN server on Ubuntu16 for almost a year. I’d like to have a VM up and running in the event of a hardware problem on the primary (hereafter “PM”). After the OVPN service is installed, what files and folders would I need to copy (or keep synchronized) to the VM so users could authenticate with the VM while the PM is repaired?

Ideally, I’d like to keep the same client config files. If the PM dies, I would change the translation rule on the firewall to point the OVPN server’s WAN IP from the PM’s internal IP to the VM’s internal IP.

Really great guide I have to say. It worked fine for me on windows, but when I tried to use it on my iOS device, after importing the profile, I was given this error: Error loading profile Missing/bad file: ta.key. Ive actually followed every single instruction through so I’m not really sure what I’m missing hope you can help me out! Also is it possible to make a script to automate creating new clients since the current ways seem waaaay too troublesome and tiring. Thanks and have a great day ahead!

Mark Drake
DigitalOcean Employee
DigitalOcean Employee badge
December 11, 2018

Hello @restinpepperoni,

Apologies for the extremely late reply, but I’ve finally gotten around to finding the cause of this error.

In Step 7, as you edit the base.conf file, you should comment out the tls-auth directive, so it looks like this:

~/client-configs/base.conf
# If a tls-auth key is used on the server
# then every client must also have the key.
#tls-auth ta.key 1

The reason for this is that you add the ta.key file’s contents directly into the client configuration file when you run the make_config.sh script later on. By not commenting it out, though, some OpenVPN clients will look for a separate file named ta.key, ignoring whatever else you have in your client1.ovpn file.

I hope that helps!

Hi, Thank you for an easy tutorial. I am able to install VPN server and connect to VPN from outside network. But I am unable to ping the machines in the network where VPN server is installed. Any changes I need to make further

A wonderful tutorial, helped me get ym first VPN up and running. As others have said, i would suggest adding alternative dns servers as alternatives to be pushed to the clients. Other than that flawless, thanks!

Thanks for the great tutorial !

I tried this on ubuntu 18.04 on google cloud. for me server didn’t start unless i change * user nobody group nogroup*

from

user nobody group nobody

in /etc/openvpn/server.conf

This was the error: ● openvpn@server.service - OpenVPN connection to server Loaded: loaded (/lib/systemd/system/openvpn@.service; disabled; vendor preset: enabled) Active: activating (auto-restart) (Result: exit-code) since Wed 2018-07-25 11:44:50 UTC; 3s ago Docs: man:openvpn(8) https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage https://community.openvpn.net/openvpn/wiki/HOWTO Process: 13283 ExecStart=/usr/sbin/openvpn --daemon ovpn-server --status /run/openvpn/server.status 10 --cd /etc/openvpn --script-secu rity 2 --config /etc/openvpn/server.conf --writepid /run/openvpn/server.pid (code=exited, status=1/FAILURE) Main PID: 13283 (code=exited, status=1/FAILURE) Status: “Pre-connection initialization successful” Jul 25 11:44:50 ovpn-instance systemd[1]: openvpn@server.service: Main process exited, code=exited, status=1/FAI LURE Jul 25 11:44:50 ovpn-instance systemd[1]: openvpn@server.service: Failed with result ‘exit-code’.

Had to edit /etc/openvpn/server.conf to enable logs by adding the line to see the logs which showed group nobody was not there.

log /var/log/openvpn/ovpn.log

Thank you for what is an excellent tutorial. i have two droplets running this (one vpn server and on CA server) on DO and it works 100%. Both are in LON1.

The only issue I have is with VPN termination. If I log into Hotmail (for example) and then log out, rather than hitting the UK MSN site, I can land at random on the Greek, Dutch or Spanish MSN page.

Is there any way to control VPN termination in this config ? Thanks for any help.

Just one thing: if you have a floating IP attached to the droplet and try to connect to the vpn using that ip then the connection will always end on timeout.

You need to uncomment the “local a.b.c.d” statement in server.conf and use the anchor IP of the droplet.

https://www.digitalocean.com/docs/networking/floating-ips/how-to/find-anchor-ips/

Are there DNS leak problems with the combination of openvpn and Ubuntu 18.04?

The 16.04 combo for me was not reliable and kept leaking my original location which renders the droplet useless. I found this article -> https://github.com/jonathanio/update-systemd-resolved which seems to be a workaround but I would rather just have the combo work.

Very good write-up. I certainly love this website. Thanks for giving the best solution about "Set Up an OpenVPN Server on Ubuntu " Jio4GVoice

Thank you for the share. showbox ps4

Great Tutorial @mdrake.

I have one question. My client is on MacOS, and was able to connect when I’m on the same wifi network as the Ubuntu VPN server; however, when I connect to my hotspot, it isn’t able to connect at all. Is there something I need to do to my IP address to get it to work? In step 8 you say, “Inside, locate the remote directive. This points the client to your OpenVPN server address — the public IP address of your OpenVPN server. If you decided to change the port that the OpenVPN server is listening on, you will also need to change 1194 to the port you selected:”

I put my public IP address in, and it didn’t connect, and so I tried my Local IP, and that worked when on my network. Am I missing something?

This is because the Public IP address is actually your router’s public IP address. So you have to configure your router to forward the VPN traffic from clients to the OpenVPN server address and associated port within your LAN. For example, configure your router to forward all the traffic (request to access port 443) to 192.168.0.1:443 (192.168.0.1 is your OpenVPN server IP address and it is listening on port 443).

Excellent Tutorial. I kindly would like to ask for some assistance, as I believe everything is working for me, but just some background info

Goal: – Enable my Ubuntu VM to act as a VPN Server, and relay Internet Connection to my host Laptop running Windows 10

I am successful enough to run the VPN Server on my Ubuntu VM, and OpenVPN GUI Client works, but when i attempt to go to Google on my host laptop, it doesn’t load.

I’m wondering could this be a networking issue? Thank you guys in advance.

Problem: Can’t seem to reach the Internet, even though VPN works.

I’m having the same problem, need some advice on how to troubleshoot this matter-

The simplest way is to use GUI app https://github.com/delfer/ssheller Open source, available for Windows, macOS и Linux. Do not require any additional app. Will configure server and download .ovpn file for you. And tested heavily with DO.

Excellent, clear tutorial.

However, after I recent upgrade I found I had to add CAP_AUDIT_WRITE to the CapabilityBoundingSet in /lib/systemd/system/openvpn@.service. There seems to be an error in the default configuration as per https://bugs.launchpad.net/ubuntu/+source/openvpn/+bug/1511524

Excellent article, helping me learn about openvpn and certificates, thanks.

Found a tiny typo. The following line:

scp pki/issued/client.crt sammy@your_server_ip:/tmp

Should be:

scp pki/issued/client1.crt sammy@your_server_ip:/tmp

Ditto, notice that when I created the VPN client config.

BTW, really excellent tutorial.

I do have a question about using two servers. Is it possible to use just one, and then remove the signing cert when / if you don’t need it?

Thank you, great guide and this got me up and running.

EasyRSA 3.0.5 is available. Tutorial has link for 3.0.4

Mistake at step 4: cp EasyRSA-3.0.4/ta.key ~/client-configs/keys/

should be: cp ~/EasyRSA-3.0.4/ta.key ~/client-configs/keys/

Hi. After successfully having OpenVPN work following the guide for Ubuntu 16.04, I wanted to upgrade to this latest setup.

Everything went good. Then I try to connect from the laptop and I get:

TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
TLS Error: TLS handshake failed

I searched and people suggest to check ufw port, which is open on the OpenVPN server

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
1194/udp                   ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
1194/udp (v6)              ALLOW       Anywhere (v6)     

A few more info. Both with 16.04 and 18.04 setup I have

  1. linux client with resolve-conf, the proper uncommented lines in ovpn file.
  2. the linux client is Ubuntu 18.10 with SSL 1.1.1 and TSL 1.3. This has no issue with the 16.04 server so I do not think is a problem at all.

Any other hint?

Thanks.

I have this exact same problem

Great tutorials!! Question: is it ok to use this OpenVPN setup to create a VPN to access private resources from Office?

what i should change with sammy@your_CA_ip? i try to change with root@myipvps. but look like its wrong.

I have a functioning OpenVPN server running on a physical Ubuntu 16 machine. I’m creating an OpenVPN virtual machine on Ubuntu 18. I installed openvpn and easy-rsa. I also rsyncd the /etc/openvpn and ~ folder (containing “openvpn-ca” and “client-configs”) from the physical machine to the VM. The “tun0” interface isn’t being created, and “systemctl status openvpn@server.service” reports the service didn’t start.

Is there something I’m missing?

This is very close to the Ubuntu 16.04 tutorial.

I chose to keep the requestor PKI under the CA PKI on the CA machine. That way I can generate artifacts in one location then distribute to hosts (clients and OpenVPN server). I’m not sure why, but I cannot re-issue configs/certs after they have been revoked. I was able to do this on Ubuntu 16.04.

I checked the index.txt DB and indeed, the serial numbers have different that the revoked serial numbers for the clients, but they are still denied by the OpenVPN server. Any idea why?

Here’s an example index.txt and CRL:

$> cat EasyRSA-3.0.4/pki/index.txt
V	281110071430Z		53B3DD36689BD7F7290714541DB6A405	unknown	/CN=server
R	281110072203Z	181113072251Z	285D0F2A0913D2D14EC2CF6A1DCC97A0	unknown	/CN=client1
R	281110072216Z	181113072254Z	0119992BD55D6F1DC7E82CA64438CE5C	unknown	/CN=client2
V	281110072320Z		6AE880868D20432A93988C4ADAA78BA8	unknown	/CN=client1
V	281110072334Z		F0313375DBE2AB77AD444F500B011493	unknown	/CN=client2
$> openssl crl -in EasyRSA-3.0.4/pki/crl.pem -text -noout
Certificate Revocation List (CRL):
        Version 2 (0x1)
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: /CN=domain
        Last Update: Nov 13 07:23:34 2018 GMT
        Next Update: Nov 10 07:23:34 2028 GMT
        CRL extensions:
            X509v3 Authority Key Identifier: 
                keyid:68:34:20:8C:1C:54:38:8E:37:5C:96:BE:17:19:73:01:50:DD:50:49
                DirName:/CN=domain
                serial:B2:30:54:18:2B:BF:2B:80

Revoked Certificates:
    Serial Number: 0119992BD55D6F1DC7E82CA64438CE5C
        Revocation Date: Nov 13 07:22:54 2018 GMT
    Serial Number: 285D0F2A0913D2D14EC2CF6A1DCC97A0
        Revocation Date: Nov 13 07:22:51 2018 GMT
    Signature Algorithm: sha256WithRSAEncryption
         0c:c1:3a:56:73:ac:c6:6c:12:8d:9f:ca:d4:41:1e:50:26:70:
         fc:f6:37:6f:fb:41:bd:68:3c:f7:0e:31:6d:55:f4:37:b3:a3:
         3e:5a:7e:3a:a0:52:1d:c5:42:7a:e6:3e:67:86:0a:b4:56:68:
         2c:0e:3a:2d:c5:32:be:d9:fd:9c:18:86:ee:a0:9f:b8:6e:a3:
         c0:ba:ad:e4:5e:34:79:0e:f4:a3:ac:11:4c:88:01:bd:90:6b:
         2e:14:3d:8d:fe:09:71:22:bf:fd:03:d4:ca:97:d7:7d:ae:7d:
         0f:91:4a:1e:7e:85:7a:21:b5:2f:80:46:ae:6a:f2:e9:42:16:
         87:e5:80:ec:fb:99:1a:36:50:1e:38:e6:35:5e:d3:01:c8:e6:
         79:05:43:64:68:dc:9b:8d:04:65:98:ae:a0:9e:ee:93:db:7a:
         0c:1e:2b:f6:6b:cb:a1:48:4a:1f:2d:23:bd:57:3c:10:0f:b5:
         ed:9d:d5:f6:f6:04:61:fe:d8:ce:3c:61:c4:ba:a3:36:e6:9d:
         dc:05:0c:fa:f6:df:0b:53:81:1e:2f:d7:d0:e9:d1:80:03:76:
         54:54:87:d4:11:80:3c:05:0d:3b:56:d8:8a:2c:4a:60:50:6e:
         07:3e:14:2d:51:57:c0:da:a7:c0:5a:6a:c9:e7:06:1a:62:3e:
         91:f1:4e:b1

Fantastic tutorial,

But I have some problems with connetion:

OpenVPN in Win10 shows: Thu Nov 15 14:49:15 2018 NOTE: --user option is not implemented on Windows Thu Nov 15 14:49:15 2018 NOTE: --group option is not implemented on Windows Thu Nov 15 14:49:15 2018 OpenVPN 2.3.18 x86_64-w64-mingw32 [SSL (OpenSSL)] [LZO] [PKCS11] [IPv6] built on Oct 26 2017 Thu Nov 15 14:49:15 2018 Windows version 6.2 (Windows 8 or greater) 64bit Thu Nov 15 14:49:15 2018 library versions: OpenSSL 1.0.2l 25 May 2017, LZO 2.10 Enter Management Password: Thu Nov 15 14:49:15 2018 MANAGEMENT: TCP Socket listening on [AF_INET]127.0.0.1:25340 Thu Nov 15 14:49:15 2018 Need hold release from management interface, waiting… Thu Nov 15 14:49:16 2018 MANAGEMENT: Client connected from [AF_INET]127.0.0.1:25340 Thu Nov 15 14:49:16 2018 MANAGEMENT: CMD ‘state on’ Thu Nov 15 14:49:16 2018 MANAGEMENT: CMD ‘log all on’ Thu Nov 15 14:49:16 2018 MANAGEMENT: CMD ‘hold off’ Thu Nov 15 14:49:16 2018 MANAGEMENT: CMD ‘hold release’ Thu Nov 15 14:49:16 2018 Control Channel Authentication: tls-auth using INLINE static key file Thu Nov 15 14:49:16 2018 Outgoing Control Channel Authentication: Using 256 bit message hash ‘SHA256’ for HMAC authentication Thu Nov 15 14:49:16 2018 Incoming Control Channel Authentication: Using 256 bit message hash ‘SHA256’ for HMAC authentication Thu Nov 15 14:49:16 2018 Socket Buffers: R=[65536->65536] S=[65536->65536] Thu Nov 15 14:49:16 2018 UDPv4 link local: [undef] Thu Nov 15 14:49:16 2018 UDPv4 link remote: [AF_INET]192.168.0.54:1194 Thu Nov 15 14:49:16 2018 MANAGEMENT: >STATE:1542289756,WAIT, Thu Nov 15 14:49:16 2018 MANAGEMENT: >STATE:1542289756,AUTH, Thu Nov 15 14:49:16 2018 TLS: Initial packet from [AF_INET]192.168.0.54:1194, sid=27589aad e0f1ff2f Thu Nov 15 14:49:16 2018 VERIFY OK: depth=1, CN=Easy-RSA CA Thu Nov 15 14:49:16 2018 Validating certificate key usage Thu Nov 15 14:49:16 2018 ++ Certificate has key usage 00a0, expects 00a0 Thu Nov 15 14:49:16 2018 VERIFY KU OK Thu Nov 15 14:49:16 2018 Validating certificate extended key usage Thu Nov 15 14:49:16 2018 ++ Certificate has EKU (str) TLS Web Server Authentication, expects TLS Web Server Authentication Thu Nov 15 14:49:16 2018 VERIFY EKU OK Thu Nov 15 14:49:16 2018 VERIFY OK: depth=0, CN=vpn Thu Nov 15 14:49:16 2018 Data Channel Encrypt: Cipher ‘AES-256-CBC’ initialized with 256 bit key Thu Nov 15 14:49:16 2018 Data Channel Encrypt: Using 256 bit message hash ‘SHA256’ for HMAC authentication Thu Nov 15 14:49:16 2018 Data Channel Decrypt: Cipher ‘AES-256-CBC’ initialized with 256 bit key Thu Nov 15 14:49:16 2018 Data Channel Decrypt: Using 256 bit message hash ‘SHA256’ for HMAC authentication Thu Nov 15 14:49:16 2018 Control Channel: TLSv1.2, cipher TLSv1/SSLv3 ECDHE-RSA-AES256-GCM-SHA384, 2048 bit RSA Thu Nov 15 14:49:16 2018 [vpn] Peer Connection Initiated with [AF_INET]192.168.0.54:1194 Thu Nov 15 14:49:17 2018 MANAGEMENT: >STATE:1542289757,GET_CONFIG, Thu Nov 15 14:49:18 2018 SENT CONTROL [vpn]: ‘PUSH_REQUEST’ (status=1) Thu Nov 15 14:49:18 2018 PUSH: Received control message: ‘PUSH_REPLY,redirect-gateway def1 bypass-dhcp,dhcp-option DNS 208.67.222.222,dhcp-option DNS 208.67.220.220,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5,peer-id 1’ Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: timers and/or timeouts modified Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: --ifconfig/up options modified Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: route options modified Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: peer-id set Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: adjusting link_mtu to 1572 Thu Nov 15 14:49:18 2018 ROUTE_GATEWAY 192.168.0.254/255.255.255.0 I=19 HWADDR=2c:56:dc:39:a4:d1 Thu Nov 15 14:49:18 2018 MANAGEMENT: Client disconnected Thu Nov 15 14:49:18 2018 There are no TAP-Windows adapters on this system. You should be able to create a TAP-Windows adapter by going to Start -> All Programs -> TAP-Windows -> Utilities -> Add a new TAP-Windows virtual ethernet adapter. Thu Nov 15 14:49:18 2018 Exiting due to fatal error

in smartphone: Failed to import profile Selected file has incorrect profile configurationta.key: cannot open for read: /storage/emulated/0/Download/ta.key

Could anyone help me?

To avoid getting a DNS leak to my ISP, I had to change my modem-router’s DNS, which was set to Automatic and it was pointing to my ISPs, which I don’t want to go through. So here I am, connecting to my own VPN and using CloudFlare’s DNS: 1.1.1.1 and 1.0.0.1.

I’ve checked through the Extended DNS leak, and all is good :)

Thanks for the Tuto maker.

Thank you, great guide and this got me up and running.

EasyRSA 3.0.5 is available. Tutorial has link for 3.0.4

Mistake at step 4: cp EasyRSA-3.0.4/ta.key ~/client-configs/keys/

should be: cp ~/EasyRSA-3.0.4/ta.key ~/client-configs/keys/

Hi. After successfully having OpenVPN work following the guide for Ubuntu 16.04, I wanted to upgrade to this latest setup.

Everything went good. Then I try to connect from the laptop and I get:

TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
TLS Error: TLS handshake failed

I searched and people suggest to check ufw port, which is open on the OpenVPN server

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
1194/udp                   ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
1194/udp (v6)              ALLOW       Anywhere (v6)     

A few more info. Both with 16.04 and 18.04 setup I have

  1. linux client with resolve-conf, the proper uncommented lines in ovpn file.
  2. the linux client is Ubuntu 18.10 with SSL 1.1.1 and TSL 1.3. This has no issue with the 16.04 server so I do not think is a problem at all.

Any other hint?

Thanks.

I have this exact same problem

Great tutorials!! Question: is it ok to use this OpenVPN setup to create a VPN to access private resources from Office?

what i should change with sammy@your_CA_ip? i try to change with root@myipvps. but look like its wrong.

I have a functioning OpenVPN server running on a physical Ubuntu 16 machine. I’m creating an OpenVPN virtual machine on Ubuntu 18. I installed openvpn and easy-rsa. I also rsyncd the /etc/openvpn and ~ folder (containing “openvpn-ca” and “client-configs”) from the physical machine to the VM. The “tun0” interface isn’t being created, and “systemctl status openvpn@server.service” reports the service didn’t start.

Is there something I’m missing?

This is very close to the Ubuntu 16.04 tutorial.

I chose to keep the requestor PKI under the CA PKI on the CA machine. That way I can generate artifacts in one location then distribute to hosts (clients and OpenVPN server). I’m not sure why, but I cannot re-issue configs/certs after they have been revoked. I was able to do this on Ubuntu 16.04.

I checked the index.txt DB and indeed, the serial numbers have different that the revoked serial numbers for the clients, but they are still denied by the OpenVPN server. Any idea why?

Here’s an example index.txt and CRL:

$> cat EasyRSA-3.0.4/pki/index.txt
V	281110071430Z		53B3DD36689BD7F7290714541DB6A405	unknown	/CN=server
R	281110072203Z	181113072251Z	285D0F2A0913D2D14EC2CF6A1DCC97A0	unknown	/CN=client1
R	281110072216Z	181113072254Z	0119992BD55D6F1DC7E82CA64438CE5C	unknown	/CN=client2
V	281110072320Z		6AE880868D20432A93988C4ADAA78BA8	unknown	/CN=client1
V	281110072334Z		F0313375DBE2AB77AD444F500B011493	unknown	/CN=client2
$> openssl crl -in EasyRSA-3.0.4/pki/crl.pem -text -noout
Certificate Revocation List (CRL):
        Version 2 (0x1)
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: /CN=domain
        Last Update: Nov 13 07:23:34 2018 GMT
        Next Update: Nov 10 07:23:34 2028 GMT
        CRL extensions:
            X509v3 Authority Key Identifier: 
                keyid:68:34:20:8C:1C:54:38:8E:37:5C:96:BE:17:19:73:01:50:DD:50:49
                DirName:/CN=domain
                serial:B2:30:54:18:2B:BF:2B:80

Revoked Certificates:
    Serial Number: 0119992BD55D6F1DC7E82CA64438CE5C
        Revocation Date: Nov 13 07:22:54 2018 GMT
    Serial Number: 285D0F2A0913D2D14EC2CF6A1DCC97A0
        Revocation Date: Nov 13 07:22:51 2018 GMT
    Signature Algorithm: sha256WithRSAEncryption
         0c:c1:3a:56:73:ac:c6:6c:12:8d:9f:ca:d4:41:1e:50:26:70:
         fc:f6:37:6f:fb:41:bd:68:3c:f7:0e:31:6d:55:f4:37:b3:a3:
         3e:5a:7e:3a:a0:52:1d:c5:42:7a:e6:3e:67:86:0a:b4:56:68:
         2c:0e:3a:2d:c5:32:be:d9:fd:9c:18:86:ee:a0:9f:b8:6e:a3:
         c0:ba:ad:e4:5e:34:79:0e:f4:a3:ac:11:4c:88:01:bd:90:6b:
         2e:14:3d:8d:fe:09:71:22:bf:fd:03:d4:ca:97:d7:7d:ae:7d:
         0f:91:4a:1e:7e:85:7a:21:b5:2f:80:46:ae:6a:f2:e9:42:16:
         87:e5:80:ec:fb:99:1a:36:50:1e:38:e6:35:5e:d3:01:c8:e6:
         79:05:43:64:68:dc:9b:8d:04:65:98:ae:a0:9e:ee:93:db:7a:
         0c:1e:2b:f6:6b:cb:a1:48:4a:1f:2d:23:bd:57:3c:10:0f:b5:
         ed:9d:d5:f6:f6:04:61:fe:d8:ce:3c:61:c4:ba:a3:36:e6:9d:
         dc:05:0c:fa:f6:df:0b:53:81:1e:2f:d7:d0:e9:d1:80:03:76:
         54:54:87:d4:11:80:3c:05:0d:3b:56:d8:8a:2c:4a:60:50:6e:
         07:3e:14:2d:51:57:c0:da:a7:c0:5a:6a:c9:e7:06:1a:62:3e:
         91:f1:4e:b1

Fantastic tutorial,

But I have some problems with connetion:

OpenVPN in Win10 shows: Thu Nov 15 14:49:15 2018 NOTE: --user option is not implemented on Windows Thu Nov 15 14:49:15 2018 NOTE: --group option is not implemented on Windows Thu Nov 15 14:49:15 2018 OpenVPN 2.3.18 x86_64-w64-mingw32 [SSL (OpenSSL)] [LZO] [PKCS11] [IPv6] built on Oct 26 2017 Thu Nov 15 14:49:15 2018 Windows version 6.2 (Windows 8 or greater) 64bit Thu Nov 15 14:49:15 2018 library versions: OpenSSL 1.0.2l 25 May 2017, LZO 2.10 Enter Management Password: Thu Nov 15 14:49:15 2018 MANAGEMENT: TCP Socket listening on [AF_INET]127.0.0.1:25340 Thu Nov 15 14:49:15 2018 Need hold release from management interface, waiting… Thu Nov 15 14:49:16 2018 MANAGEMENT: Client connected from [AF_INET]127.0.0.1:25340 Thu Nov 15 14:49:16 2018 MANAGEMENT: CMD ‘state on’ Thu Nov 15 14:49:16 2018 MANAGEMENT: CMD ‘log all on’ Thu Nov 15 14:49:16 2018 MANAGEMENT: CMD ‘hold off’ Thu Nov 15 14:49:16 2018 MANAGEMENT: CMD ‘hold release’ Thu Nov 15 14:49:16 2018 Control Channel Authentication: tls-auth using INLINE static key file Thu Nov 15 14:49:16 2018 Outgoing Control Channel Authentication: Using 256 bit message hash ‘SHA256’ for HMAC authentication Thu Nov 15 14:49:16 2018 Incoming Control Channel Authentication: Using 256 bit message hash ‘SHA256’ for HMAC authentication Thu Nov 15 14:49:16 2018 Socket Buffers: R=[65536->65536] S=[65536->65536] Thu Nov 15 14:49:16 2018 UDPv4 link local: [undef] Thu Nov 15 14:49:16 2018 UDPv4 link remote: [AF_INET]192.168.0.54:1194 Thu Nov 15 14:49:16 2018 MANAGEMENT: >STATE:1542289756,WAIT, Thu Nov 15 14:49:16 2018 MANAGEMENT: >STATE:1542289756,AUTH, Thu Nov 15 14:49:16 2018 TLS: Initial packet from [AF_INET]192.168.0.54:1194, sid=27589aad e0f1ff2f Thu Nov 15 14:49:16 2018 VERIFY OK: depth=1, CN=Easy-RSA CA Thu Nov 15 14:49:16 2018 Validating certificate key usage Thu Nov 15 14:49:16 2018 ++ Certificate has key usage 00a0, expects 00a0 Thu Nov 15 14:49:16 2018 VERIFY KU OK Thu Nov 15 14:49:16 2018 Validating certificate extended key usage Thu Nov 15 14:49:16 2018 ++ Certificate has EKU (str) TLS Web Server Authentication, expects TLS Web Server Authentication Thu Nov 15 14:49:16 2018 VERIFY EKU OK Thu Nov 15 14:49:16 2018 VERIFY OK: depth=0, CN=vpn Thu Nov 15 14:49:16 2018 Data Channel Encrypt: Cipher ‘AES-256-CBC’ initialized with 256 bit key Thu Nov 15 14:49:16 2018 Data Channel Encrypt: Using 256 bit message hash ‘SHA256’ for HMAC authentication Thu Nov 15 14:49:16 2018 Data Channel Decrypt: Cipher ‘AES-256-CBC’ initialized with 256 bit key Thu Nov 15 14:49:16 2018 Data Channel Decrypt: Using 256 bit message hash ‘SHA256’ for HMAC authentication Thu Nov 15 14:49:16 2018 Control Channel: TLSv1.2, cipher TLSv1/SSLv3 ECDHE-RSA-AES256-GCM-SHA384, 2048 bit RSA Thu Nov 15 14:49:16 2018 [vpn] Peer Connection Initiated with [AF_INET]192.168.0.54:1194 Thu Nov 15 14:49:17 2018 MANAGEMENT: >STATE:1542289757,GET_CONFIG, Thu Nov 15 14:49:18 2018 SENT CONTROL [vpn]: ‘PUSH_REQUEST’ (status=1) Thu Nov 15 14:49:18 2018 PUSH: Received control message: ‘PUSH_REPLY,redirect-gateway def1 bypass-dhcp,dhcp-option DNS 208.67.222.222,dhcp-option DNS 208.67.220.220,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5,peer-id 1’ Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: timers and/or timeouts modified Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: --ifconfig/up options modified Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: route options modified Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: peer-id set Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: adjusting link_mtu to 1572 Thu Nov 15 14:49:18 2018 ROUTE_GATEWAY 192.168.0.254/255.255.255.0 I=19 HWADDR=2c:56:dc:39:a4:d1 Thu Nov 15 14:49:18 2018 MANAGEMENT: Client disconnected Thu Nov 15 14:49:18 2018 There are no TAP-Windows adapters on this system. You should be able to create a TAP-Windows adapter by going to Start -> All Programs -> TAP-Windows -> Utilities -> Add a new TAP-Windows virtual ethernet adapter. Thu Nov 15 14:49:18 2018 Exiting due to fatal error

in smartphone: Failed to import profile Selected file has incorrect profile configurationta.key: cannot open for read: /storage/emulated/0/Download/ta.key

Could anyone help me?

To avoid getting a DNS leak to my ISP, I had to change my modem-router’s DNS, which was set to Automatic and it was pointing to my ISPs, which I don’t want to go through. So here I am, connecting to my own VPN and using CloudFlare’s DNS: 1.1.1.1 and 1.0.0.1.

I’ve checked through the Extended DNS leak, and all is good :)

Thanks for the Tuto maker.

Thank you, great guide and this got me up and running.

EasyRSA 3.0.5 is available. Tutorial has link for 3.0.4

Mistake at step 4: cp EasyRSA-3.0.4/ta.key ~/client-configs/keys/

should be: cp ~/EasyRSA-3.0.4/ta.key ~/client-configs/keys/

Hi. After successfully having OpenVPN work following the guide for Ubuntu 16.04, I wanted to upgrade to this latest setup.

Everything went good. Then I try to connect from the laptop and I get:

TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
TLS Error: TLS handshake failed

I searched and people suggest to check ufw port, which is open on the OpenVPN server

$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
1194/udp                   ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
1194/udp (v6)              ALLOW       Anywhere (v6)     

A few more info. Both with 16.04 and 18.04 setup I have

  1. linux client with resolve-conf, the proper uncommented lines in ovpn file.
  2. the linux client is Ubuntu 18.10 with SSL 1.1.1 and TSL 1.3. This has no issue with the 16.04 server so I do not think is a problem at all.

Any other hint?

Thanks.

I have this exact same problem

Great tutorials!! Question: is it ok to use this OpenVPN setup to create a VPN to access private resources from Office?

what i should change with sammy@your_CA_ip? i try to change with root@myipvps. but look like its wrong.

I have a functioning OpenVPN server running on a physical Ubuntu 16 machine. I’m creating an OpenVPN virtual machine on Ubuntu 18. I installed openvpn and easy-rsa. I also rsyncd the /etc/openvpn and ~ folder (containing “openvpn-ca” and “client-configs”) from the physical machine to the VM. The “tun0” interface isn’t being created, and “systemctl status openvpn@server.service” reports the service didn’t start.

Is there something I’m missing?

This is very close to the Ubuntu 16.04 tutorial.

I chose to keep the requestor PKI under the CA PKI on the CA machine. That way I can generate artifacts in one location then distribute to hosts (clients and OpenVPN server). I’m not sure why, but I cannot re-issue configs/certs after they have been revoked. I was able to do this on Ubuntu 16.04.

I checked the index.txt DB and indeed, the serial numbers have different that the revoked serial numbers for the clients, but they are still denied by the OpenVPN server. Any idea why?

Here’s an example index.txt and CRL:

$> cat EasyRSA-3.0.4/pki/index.txt
V	281110071430Z		53B3DD36689BD7F7290714541DB6A405	unknown	/CN=server
R	281110072203Z	181113072251Z	285D0F2A0913D2D14EC2CF6A1DCC97A0	unknown	/CN=client1
R	281110072216Z	181113072254Z	0119992BD55D6F1DC7E82CA64438CE5C	unknown	/CN=client2
V	281110072320Z		6AE880868D20432A93988C4ADAA78BA8	unknown	/CN=client1
V	281110072334Z		F0313375DBE2AB77AD444F500B011493	unknown	/CN=client2
$> openssl crl -in EasyRSA-3.0.4/pki/crl.pem -text -noout
Certificate Revocation List (CRL):
        Version 2 (0x1)
    Signature Algorithm: sha256WithRSAEncryption
        Issuer: /CN=domain
        Last Update: Nov 13 07:23:34 2018 GMT
        Next Update: Nov 10 07:23:34 2028 GMT
        CRL extensions:
            X509v3 Authority Key Identifier: 
                keyid:68:34:20:8C:1C:54:38:8E:37:5C:96:BE:17:19:73:01:50:DD:50:49
                DirName:/CN=domain
                serial:B2:30:54:18:2B:BF:2B:80

Revoked Certificates:
    Serial Number: 0119992BD55D6F1DC7E82CA64438CE5C
        Revocation Date: Nov 13 07:22:54 2018 GMT
    Serial Number: 285D0F2A0913D2D14EC2CF6A1DCC97A0
        Revocation Date: Nov 13 07:22:51 2018 GMT
    Signature Algorithm: sha256WithRSAEncryption
         0c:c1:3a:56:73:ac:c6:6c:12:8d:9f:ca:d4:41:1e:50:26:70:
         fc:f6:37:6f:fb:41:bd:68:3c:f7:0e:31:6d:55:f4:37:b3:a3:
         3e:5a:7e:3a:a0:52:1d:c5:42:7a:e6:3e:67:86:0a:b4:56:68:
         2c:0e:3a:2d:c5:32:be:d9:fd:9c:18:86:ee:a0:9f:b8:6e:a3:
         c0:ba:ad:e4:5e:34:79:0e:f4:a3:ac:11:4c:88:01:bd:90:6b:
         2e:14:3d:8d:fe:09:71:22:bf:fd:03:d4:ca:97:d7:7d:ae:7d:
         0f:91:4a:1e:7e:85:7a:21:b5:2f:80:46:ae:6a:f2:e9:42:16:
         87:e5:80:ec:fb:99:1a:36:50:1e:38:e6:35:5e:d3:01:c8:e6:
         79:05:43:64:68:dc:9b:8d:04:65:98:ae:a0:9e:ee:93:db:7a:
         0c:1e:2b:f6:6b:cb:a1:48:4a:1f:2d:23:bd:57:3c:10:0f:b5:
         ed:9d:d5:f6:f6:04:61:fe:d8:ce:3c:61:c4:ba:a3:36:e6:9d:
         dc:05:0c:fa:f6:df:0b:53:81:1e:2f:d7:d0:e9:d1:80:03:76:
         54:54:87:d4:11:80:3c:05:0d:3b:56:d8:8a:2c:4a:60:50:6e:
         07:3e:14:2d:51:57:c0:da:a7:c0:5a:6a:c9:e7:06:1a:62:3e:
         91:f1:4e:b1

Fantastic tutorial,

But I have some problems with connetion:

OpenVPN in Win10 shows: Thu Nov 15 14:49:15 2018 NOTE: --user option is not implemented on Windows Thu Nov 15 14:49:15 2018 NOTE: --group option is not implemented on Windows Thu Nov 15 14:49:15 2018 OpenVPN 2.3.18 x86_64-w64-mingw32 [SSL (OpenSSL)] [LZO] [PKCS11] [IPv6] built on Oct 26 2017 Thu Nov 15 14:49:15 2018 Windows version 6.2 (Windows 8 or greater) 64bit Thu Nov 15 14:49:15 2018 library versions: OpenSSL 1.0.2l 25 May 2017, LZO 2.10 Enter Management Password: Thu Nov 15 14:49:15 2018 MANAGEMENT: TCP Socket listening on [AF_INET]127.0.0.1:25340 Thu Nov 15 14:49:15 2018 Need hold release from management interface, waiting… Thu Nov 15 14:49:16 2018 MANAGEMENT: Client connected from [AF_INET]127.0.0.1:25340 Thu Nov 15 14:49:16 2018 MANAGEMENT: CMD ‘state on’ Thu Nov 15 14:49:16 2018 MANAGEMENT: CMD ‘log all on’ Thu Nov 15 14:49:16 2018 MANAGEMENT: CMD ‘hold off’ Thu Nov 15 14:49:16 2018 MANAGEMENT: CMD ‘hold release’ Thu Nov 15 14:49:16 2018 Control Channel Authentication: tls-auth using INLINE static key file Thu Nov 15 14:49:16 2018 Outgoing Control Channel Authentication: Using 256 bit message hash ‘SHA256’ for HMAC authentication Thu Nov 15 14:49:16 2018 Incoming Control Channel Authentication: Using 256 bit message hash ‘SHA256’ for HMAC authentication Thu Nov 15 14:49:16 2018 Socket Buffers: R=[65536->65536] S=[65536->65536] Thu Nov 15 14:49:16 2018 UDPv4 link local: [undef] Thu Nov 15 14:49:16 2018 UDPv4 link remote: [AF_INET]192.168.0.54:1194 Thu Nov 15 14:49:16 2018 MANAGEMENT: >STATE:1542289756,WAIT, Thu Nov 15 14:49:16 2018 MANAGEMENT: >STATE:1542289756,AUTH, Thu Nov 15 14:49:16 2018 TLS: Initial packet from [AF_INET]192.168.0.54:1194, sid=27589aad e0f1ff2f Thu Nov 15 14:49:16 2018 VERIFY OK: depth=1, CN=Easy-RSA CA Thu Nov 15 14:49:16 2018 Validating certificate key usage Thu Nov 15 14:49:16 2018 ++ Certificate has key usage 00a0, expects 00a0 Thu Nov 15 14:49:16 2018 VERIFY KU OK Thu Nov 15 14:49:16 2018 Validating certificate extended key usage Thu Nov 15 14:49:16 2018 ++ Certificate has EKU (str) TLS Web Server Authentication, expects TLS Web Server Authentication Thu Nov 15 14:49:16 2018 VERIFY EKU OK Thu Nov 15 14:49:16 2018 VERIFY OK: depth=0, CN=vpn Thu Nov 15 14:49:16 2018 Data Channel Encrypt: Cipher ‘AES-256-CBC’ initialized with 256 bit key Thu Nov 15 14:49:16 2018 Data Channel Encrypt: Using 256 bit message hash ‘SHA256’ for HMAC authentication Thu Nov 15 14:49:16 2018 Data Channel Decrypt: Cipher ‘AES-256-CBC’ initialized with 256 bit key Thu Nov 15 14:49:16 2018 Data Channel Decrypt: Using 256 bit message hash ‘SHA256’ for HMAC authentication Thu Nov 15 14:49:16 2018 Control Channel: TLSv1.2, cipher TLSv1/SSLv3 ECDHE-RSA-AES256-GCM-SHA384, 2048 bit RSA Thu Nov 15 14:49:16 2018 [vpn] Peer Connection Initiated with [AF_INET]192.168.0.54:1194 Thu Nov 15 14:49:17 2018 MANAGEMENT: >STATE:1542289757,GET_CONFIG, Thu Nov 15 14:49:18 2018 SENT CONTROL [vpn]: ‘PUSH_REQUEST’ (status=1) Thu Nov 15 14:49:18 2018 PUSH: Received control message: ‘PUSH_REPLY,redirect-gateway def1 bypass-dhcp,dhcp-option DNS 208.67.222.222,dhcp-option DNS 208.67.220.220,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5,peer-id 1’ Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: timers and/or timeouts modified Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: --ifconfig/up options modified Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: route options modified Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: peer-id set Thu Nov 15 14:49:18 2018 OPTIONS IMPORT: adjusting link_mtu to 1572 Thu Nov 15 14:49:18 2018 ROUTE_GATEWAY 192.168.0.254/255.255.255.0 I=19 HWADDR=2c:56:dc:39:a4:d1 Thu Nov 15 14:49:18 2018 MANAGEMENT: Client disconnected Thu Nov 15 14:49:18 2018 There are no TAP-Windows adapters on this system. You should be able to create a TAP-Windows adapter by going to Start -> All Programs -> TAP-Windows -> Utilities -> Add a new TAP-Windows virtual ethernet adapter. Thu Nov 15 14:49:18 2018 Exiting due to fatal error

in smartphone: Failed to import profile Selected file has incorrect profile configurationta.key: cannot open for read: /storage/emulated/0/Download/ta.key

Could anyone help me?

To avoid getting a DNS leak to my ISP, I had to change my modem-router’s DNS, which was set to Automatic and it was pointing to my ISPs, which I don’t want to go through. So here I am, connecting to my own VPN and using CloudFlare’s DNS: 1.1.1.1 and 1.0.0.1.

I’ve checked through the Extended DNS leak, and all is good :)

Thanks for the Tuto maker.

Hi, I managed to follow the steps on Mac OSX till step 10. when i tried to launch the client1.ovpn with tunnelblick im getting this error message.

"Installation failed:

At line 96 of the OpenVPN configuration file: The configuration file refers to a file

ca.crt

which should be located at

/Users/Harein/ca.crt

but the file does not exist."

I tried to transfer the file from my server and the CA machine but im getting permission denied or the file does not exist. Im not sure what to do.

Mark Drake
DigitalOcean Employee
DigitalOcean Employee badge
December 11, 2018

Hello @Harein,

I can’t be sure exactly what’s happening on your machine, but it looks like Tunnelblick is looking for the ca.crt file on your machine. However, that file’s contents should have been copied directly into the client1.ovpn file when you ran the make_config.sh script.

I’d recommend that you double check that the ca ca.crt directive is commented out in your client1.ovpn file, like this:

client1.ovpn
# 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

That was exactly it!

I feel kinda stupid, not sure how I overlooked that step haha.

Thank you so much @mdrake!

I have followed this twice verbatim, and client fails from a WinComp w/ OpenVPN.

Everything before Step 10 would indicate things are working as they “should” Server up and running, can FTP to client#.opvn Script produces new client#.opvn in the ~/files

This is the new error, starting completely over. NOTE: --group option is not implemented on Windows Options error: You must define CA file (–ca) or CA path (–capath) Use --help for more information.

Adding/removing “#” in front of user or group does nothing to change this issue.

Again, everything “looks” exactly the same in terms of “nano any_file” Copy and pasted every command this time…

I am getting more confused by the second, since people say this is suppose to my copy/paste/work. “troubleshooting” is not getting me anywhere since I don’t know what to fix.

Yesterday it was: OpenSSL: error:0B080074:x509 certificate routines:X509_check_private_key:key values mismatch Cannot load private key file [[INLINE]] SIGUSR1[soft,private-key-password-failure] received, process restarting MANAGEMENT: >STATE:1544840062,RECONNECTING,private-key-password-failure,

Time to blow it all out and try from scratch and maybe the copy/paste fail will show itself.

If anyone as an idea of what I am CLEARLY missing…

Mark Drake
DigitalOcean Employee
DigitalOcean Employee badge
December 17, 2018

Hello @benjamin0c2fa5ce143121382e,

I’m sorry to hear that you’re running into trouble with setting up OpenVPN. I just ran through the tutorial as it’s written and I wasn’t able to replicate any of the errors you’ve mentioned here on a Windows machine.

Based on those error messages you’ve shared, it looks like OpenVPN is registering an error between your private key file, ca.key, and your public certificate file, ca.crt. The contents of ca.crt (along with the contents of the client.crt, client.key, and ta.key files) should have been copied directly into client#.ovpn when you created that file using the make_config.sh script. Can you confirm that those file contents are all in your client#.ovpn file?

Tried again, and now: Options error: Unrecognized option or missing or extra parameter(s) in Benji.ovpn:47: try (2.4.6) Use --help for more information.

Looking into this currently. But, this error does provide hope compared to the last two. I believe the issue was indeed cp, and me not verifying that files were making it each time to appropriate locations.

This comment has been deleted

    This comment has been deleted

      Hi @mdrake - I was able to setup the VPN on my Raspberry Pi running Ubuntu 18.04. When I try to connect from an outside network the Tunnelblick status is stuck at “Waiting for server response”. Any hints on troubleshooting? (My client is MacOS Mojave)

      I spent the entire afternoon only to arrive in the end (in OpenVPN GUI) to:

      Wed Jan 02 20:54:02 2019 MANAGEMENT: CMD ‘state on’ Wed Jan 02 20:54:02 2019 MANAGEMENT: CMD ‘log all on’ Wed Jan 02 20:54:02 2019 MANAGEMENT: CMD ‘echo all on’ Wed Jan 02 20:54:02 2019 MANAGEMENT: CMD ‘bytecount 5’ Wed Jan 02 20:54:02 2019 MANAGEMENT: CMD ‘hold off’ Wed Jan 02 20:54:02 2019 MANAGEMENT: CMD ‘hold release’ Wed Jan 02 20:54:02 2019 OpenSSL: error:0906D06C:PEM routines:PEM_read_bio:no start line Wed Jan 02 20:54:02 2019 OpenSSL: error:140AD009:SSL routines:SSL_CTX_use_certificate_file:PEM lib Wed Jan 02 20:54:02 2019 MANAGEMENT: Client disconnected Wed Jan 02 20:54:02 2019 Cannot load inline certificate file Wed Jan 02 20:54:02 2019 Exiting due to fatal error

      Mark Drake
      DigitalOcean Employee
      DigitalOcean Employee badge
      January 3, 2019

      Hello @webmasterb0b603e7fb2a1c88a,

      I just went through the tutorial as it’s written and I couldn’t replicate your error. I successfully tested out the connection to the OpenVPN server from a Windows Machine and was able to browse the internet over the VPN.

      The contents of your ca.crt, client.crt, client.key, and ta.key files should have been copied directly into client1.ovpn when you created that file using the make_config.sh script. Based on the output you’ve provided, though, it looks like the OpenVPN client isn’t able to read one of these. Can you confirm that those file contents are all included in your client1.ovpn file?

      I am unfortunate, I encountered the following error in the operation, the first is chown root.rnd, prompted me to access this file and this directory, the second problem is to use ./make_config.sh client1, generate client1.ovpn Prompt me not cat: /root/client-configs/keys/ca.crt: No such file or directory Cat: /root/client-configs/keys/client1.crt: No such file or directory Cat: /root/client-configs/keys/client1.key: No such file or directory Cat: /root/client-configs/keys/ta.key: No such file or directory Other places and tutorials are all right, please tell me how to solve it, thank you.

      hey, you shouldn’t be doing it via root. can you check, do you have these files in the folder? I’ve got similar error and it turned out i forgot to meve ca.crt and ta.key to the keys folder.

      Hello, got an issue on the server after following the guide. After testing VPN (successfully), SSH connect stopped working, as well as VPN. The error if following if I try to connect via mac os CMD. ssh: connect to host 142.93.52.84 port 22: Can’t assign requested address

      server is working and i’m able to connect via other server. Could you suggest what it may be? Firewall?

      You should make note that when people are using Floating IP addresses they must change their config to use their Dropplet’s Anchor IP address…

      https://www.digitalocean.com/docs/networking/floating-ips/how-to/find-anchor-ips/

      #/etc/openvpn/server.conf
      local <anchorIP>
      

      Otherwise you will get:

      TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
      TLS Error: TLS handshake failed
      

      Hi @mdrake! First off, would like to thank you for the really wonderful article. You’ve made setting up an OpenVPN much easier and understandable!

      Thanks for “helping” out with my first mini project! Kudos!

      However, one question similar to @KashifBaksh’s: I’m able to connect to the VPN successfully, however can’t ping to any hosts in the network my OpenVPN server is located. Is there further routing(s) that has to be done?

      Thank you for making this! Is there another tutorial that lays out the steps of adding another client?

      Mark Drake
      DigitalOcean Employee
      DigitalOcean Employee badge
      February 25, 2019

      Hello @cyberandrew! No, we do not have a separate tutorial for adding another client. However, you can add another client by following steps 4 and 9-11 for every additional device you want to connect to the VPN.

      Hi mdrake, great tutorial!!

      I tried to start and enable the server, but it won´t work. I got this information:

      ● openvpn@server.service - OpenVPN connection to server Loaded: loaded (/lib/systemd/system/openvpn@.service; indirect; vendor preset: enabled) Active: activating (auto-restart) (Result: exit-code) since Thu 2019-02-14 19:58:37 UTC; 56ms ago Docs: man:openvpn(8) https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage https://community.openvpn.net/openvpn/wiki/HOWTO Process: 1279 ExecStart=/usr/sbin/openvpn --daemon ovpn-server --status /run/openvpn/server.status 10 --cd /etc/openvpn --script-security 2 --config /etc/op Main PID: 1279 (code=exited, status=1/FAILURE) Status: “Pre-connection initialization successful”

      The logs are empty! It seems to faile at the starting point. Do you have any idea?

      Thx Marc

      What might be causing this problem:

      Options error: Unrecognized option or missing or extra parameter(s) in client1.ovpn:136: < (2.4.4) Use --help for more information

      136 is just after:

      script-security 2 up /etc/openvpn/update-resolv-conf down /etc/openvpn/update-resolv-conf <ca>

      Thanks for great tutorial.

      I was able to do it. And it’s working if the device is within same network of my own VPN server but when I transfer to different network. The VPN is not working.

      Great tutorial! I missed instructions on ipv6 though – can you expand the tutorial to add support for it?

      @mdrake Thank you for the tutorial; I found it very helpful. But I have to admit I have run into a bit of an issue and was hoping you might be able to shed some light on what I’ve missed.

      I have repeated the process about three times and endup at the same result.
      " TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)" “TLS Error: TLS handshake failed”

      Checked the firewall, checked the logs have used seperate devices/servers to try to connect. Really banging my head against a wall.

      Quick overview of infrastructure: CloudFlare [CDN : SSL : Domain Name] => || (VPC) Public IP Router => private VPN / Web server

      I can ftp & ssh in with no problems and when the server was a openvpn client not a openvpn server it worked just fine.

      From what I can tell… disclaimer… I am very new to this, but it looks as though I am not even making it to the VPN server. But like I said I have tried different devices to try to connect and no love.

      If you don’t mind dropping me a note, I would love to resolve this. I assume it is an OPE on my end.

      Our ultimate goal is to have a VPN platform where our team can access an internal web server via OpenVPN. So definitely could use your input.

      Thank you in advance, I look forward to hearing from you.

      Mark Drake
      DigitalOcean Employee
      DigitalOcean Employee badge
      April 23, 2019

      Hello @Europital,

      Thank you for your comment, and my apologies for taking so long to respond to you.

      I’m sorry you’re having trouble getting your OpenVPN connection to work correctly. I can’t say with any certainty what could be causing the issue, but it may have something to do with your infrastructure setup. This tutorial was written with a very specific infrastructure in mind (one server + one CA machine) so it’s possible that your Cloudflare CDN or your VPC router need some further configuration to allow OpenVPN to function as expected.

      Also, if it’s helpful, the OpenVPN project website has this page that describes your TLS error. It may be worthwhile to try out the suggestions on that page to see of one of them can resolve your error.

      Hi @mdrake, Thank you for the follow-up.

      As it stands now, I am using the server as a vpn client and accessing which is too bad as all vpn traffic is routed through our vpn server and as such the logs only show the vpn server activity. Ideally I would like to see which users ip were accessing the server. But ok it works, I am operational so it is what it is.

      Should I find a way to solve my problem I will be sure to update my post so I can share with the community.

      Again thanks for the input and follow-up.

      Cheers!

      This really is a good tutorial. I signed up with a DO community account just to say that.

      Hi i was an Error when run : sudo openvpn --config client1.ovpn error is: Tue Apr 9 14:56:21 2019 TCP/UDP: Preserving recently used remote address: [AF_INET]188.166.13.133:1194 Tue Apr 9 14:56:21 2019 Socket Buffers: R=[212992->212992] S=[212992->212992] Tue Apr 9 14:56:21 2019 UDP link local: (not bound) Tue Apr 9 14:56:21 2019 UDP link remote: [AF_INET]188.166.13.133:1194 Tue Apr 9 14:56:21 2019 NOTE: UID/GID downgrade will be delayed because of --client, --pull, or --up-delay Tue Apr 9 14:57:21 2019 TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity) Tue Apr 9 14:57:21 2019 TLS Error: TLS handshake failed Tue Apr 9 14:57:21 2019 SIGUSR1[soft,tls-error] received, process restarting Tue Apr 9 14:57:21 2019 Restart pause, 5 second(s)

      how to I fix this? thanks

      Mark Drake
      DigitalOcean Employee
      DigitalOcean Employee badge
      April 23, 2019

      Hello @zshahab91,

      Thank you for your comment! I just went through the tutorial myself and I wasn’t able to replicate that error, although I do know it’s a very commonly seen error in OpenVPN.

      I can’t say with any certainty what exactly is causing this issue for you, but the OpenVPN website provides this page which offers some suggestions for how to resolve this error. I would recommend that you review and test out those suggestions, in addition to going back and ensuring that you’ve correctly updated all the necessary files as described in this tutorial.

      Hello, I followed this tutorial to set my OpenVPN server. I configured everything and tested on android client. It connects, but when I try to access the other devices from my local network, this will not connect to them. For example, when I try to connect to my Jira server (192.168.1.x) the web page will not be opened, instead will throw an error that it could not connect to the instance or I don’t have permissions to access it. Can help me someone with this problem?

      Thank you

      Thank you for theexplanation. After trying a few times, i finally finish the steps. but i cannot connect to my OpenVPN server, it keeps give me this on OpenVPN log:

      Authenticate/Decrypt packet error: packet HMAC authentication failed
      TLS Error: incoming packet authentication failed from [AF_INET]
      

      i tried to generate new key, but the results still the same. any comment would be really helpful. thank you, have a nice day everyone

      Quite peeved I can’t access the old version of this tutorial…

      I have successfully got openvpn running on ubuntu 18 using this tutorial. However, I realised that the IP given in the before.rules files (NAT table tules) prevents any connected party from actually gaining access to the target network the VPN serves. I changed the IP address in the /etc/ufw/before.rules file, and restarted the server, but the tun0 still shows the IP used in the tutorial 10.8.0.8/8, and a client that connects still gets an Ip the the 10.8.0 range. How can I change this. I do not want to have to go through the whole setup again!

      UPDATE: So I needed to add a rule to do the mapping the the ufw config file, and it works! I have the script by [sutherland]to only generate the client_configs, which was so much less work that the manual process.

      This is an excellent tutorial and whilst I have followed it and everything is detailed very well there are still a lot of people that struggle with getting things like this set up, to pay back too the community I have created an automated script that follows this Digital Ocean guide without the need to have two servers set up. For those that would like to automate the above guide please check out my script at https://scripting.online/auto-install-openvpn-18-04

      Thanks! I’ve successfully used a part of your script to generate client config files.

      Excellent tutorial! I have followed all steps and it works fine! I have question for the more experienced users. Using the settings as in this tutorial any client connected to the VPN is able to see the other devices on the same LAN as the server. How can I allow the clients connected to the VPN to ONLY have access to the outside internet and NO access to the server’s LAN? Thank you.

      Can the 2nd machine that serves as a CA be a local machine (Ubuntu VM)? Once it generates the certs, it doesn’t need to be online, correct?

      Mark Drake
      DigitalOcean Employee
      DigitalOcean Employee badge
      June 20, 2019

      Hello @pels5423, and thank you for your question.

      As far as I know, any machine can be used as the certificate authority in this kind of setup - including a regular laptop or even a virtual machine. However, this page on the OpenVPN Community Wiki recommends against using a VM as the certificate authority, as VMs tend to lack a good entropy source for random data. That may not be important for your needs, but it is a security factor worth considering.

      honestly this was extremely difficult to follow because of the whole CA server, openvpn server, client configuration, client vpn setup…

      After googling and reading about it, I can understand the need for security and having two different servers for certificates and the vpn, but I do not think that the average user will ever have the need to go that far.

      For almost every business or individual, compromised access to their VPN server might as well be the worst case scenario. Maybe that is not the case for extremely big companies with multiple servers to manage, but the average user will feel no difference between having a compromised vps that had the certificate authority on it, and a compromised vps that didn’t.

      I would really appreciate it if there was a variant of this tutorial without the whole extra back and forth between servers. regardless I still have to thank you for the effort put in this post.

      Mark Drake
      DigitalOcean Employee
      DigitalOcean Employee badge
      June 21, 2019

      Hello @k1ngzee, and thank you for your feedback.

      We recommend the process outlined in this guide because it’s worth the extra time it takes to ensure that your root certificate won’t be compromised. Otherwise you run the risk of someone you don’t know gaining access to your VPN. As you wrote, this may not be a major concern for some individuals, but it’s an important step for anyone trying to mask their browsing activity with a VPN.

      Great tutorial. This worked perfectly for me.

      I personally don’t like the idea of a .openvpn file being generated without a password, as it means that anyone who gets their hands on that file can connect to the VPN.

      In “Step 4”, I would recommend NOT including the nopass option:

      Change this:

      ./easyrsa gen-req client1 nopass
      

      to this:

      ./easyrsa gen-req client1
      

      You’ll then be prompted for a password:

      Enter PEM pass phrase:
      Verifying - Enter PEM pass phrase:
      

      When you do this, when your VPN client attempts to connect, it’s prompted to enter the password.

      How to make site-to-site VPN from these instructions?

      Thanks so much for this! For me it worked the first time. Now I am going to further test things by adding more clients. My first client (client1) is an linux mint system (18 Sarah) - next I’ll try my android phone. The linux mint system worked without any modifications to the client1.ovpn file.

      Client2 (my android phone) is working now too!

      Thank you for writing this tutorial. I could connect to the server from a remote computer running on windows but i cant seem to reroute the traffic correctly since i cannot browse the web i get a lot of timeouts(ERR_CONNECTION_TIMED_OUT).

      EDIT: I found the mistake, i forgot to change the adapter in the before.rules to the correct one. I hope this helps people when they are troubleshooting this issue.

      Hi there, thanks for the great tutorial. I setup an Ubuntu 18.04 openvpn server using aws and a KDEneon 18.04 client. Everything works fine, I can successfully connect to the VPN. However, when using DNSLeakTest, it turned out that although my IP corresponds to my server’s region (UK in this case) my VPN is leaking and my ISPs servers are shown. I fixed that problem by manually assigning the DNS servers 208.67.222.222 and 208.67.220.220 in the network manager. Now, I can pass all the tests on DNSLeakTest and I can use for example the BBCiplayer. Netflix UK though doesn’t work (I can just use my region’s version). When I look up my IP on whatismyipaddress.com, I can still see my ISP’s location. That’s confusing. Any ideas?

      I made all steps, I started the openvpn, I created the client, i tested if my server was good using:

      nc -vu 3x.xxx.xx.xx 1194
      Connection to 3x.xxx.xx.xx 1194 port [udp/openvpn] succeeded!
      

      But still cannot connect from my GNU/Linux desktop. I always have this:

      Thu Sep  5 01:15:34 2019 OpenVPN 2.4.4 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on May 14 2019
      Thu Sep  5 01:15:34 2019 library versions: OpenSSL 1.1.1  11 Sep 2018, LZO 2.08
      Thu Sep  5 01:15:34 2019 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
      Thu Sep  5 01:15:34 2019 Outgoing Control Channel Authentication: Using 256 bit message hash 'SHA256' for HMAC authentication
      Thu Sep  5 01:15:34 2019 Incoming Control Channel Authentication: Using 256 bit message hash 'SHA256' for HMAC authentication
      Thu Sep  5 01:15:34 2019 TCP/UDP: Preserving recently used remote address: [AF_INET]3x.xxx.xxx.xx:1194
      Thu Sep  5 01:15:34 2019 Socket Buffers: R=[212992->212992] S=[212992->212992]
      Thu Sep  5 01:15:34 2019 UDP link local: (not bound)
      Thu Sep  5 01:15:34 2019 UDP link remote: [AF_INET]3x.xxx.xxx.xx:1194
      Thu Sep  5 01:15:34 2019 NOTE: UID/GID downgrade will be delayed because of --client, --pull, or --up-delay
      Thu Sep  5 01:16:34 2019 TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
      Thu Sep  5 01:16:34 2019 TLS Error: TLS handshake failed
      Thu Sep  5 01:16:34 2019 SIGUSR1[soft,tls-error] received, process restarting
      Thu Sep  5 01:16:34 2019 Restart pause, 5 second(s)
      Thu Sep  5 01:16:39 2019 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
      Thu Sep  5 01:16:39 2019 TCP/UDP: Preserving recently used remote address: [AF_INET]3x.xxx.xxx.xx:1194
      Thu Sep  5 01:16:39 2019 Socket Buffers: R=[212992->212992] S=[212992->212992]
      Thu Sep  5 01:16:39 2019 UDP link local: (not bound)
      Thu Sep  5 01:16:39 2019 UDP link remote: [AF_INET]3x.xxx.xxx.xx:1194
      

      I suppose that this lines are the problem:

      TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
      Thu Sep  5 01:16:34 2019 TLS Error: TLS handshake failed
      
      Mark Drake
      DigitalOcean Employee
      DigitalOcean Employee badge
      September 12, 2019

      Hello @jamesxt94,

      I just completed the tutorial as it’s written and I was able to get the OpenVPN server up and running successfully. That said, as I’ve gone through this process a number of times over the course of working on this tutorial, I’ve encountered the error TLS Error: TLS handshake failed many times. Believe me when I say I know how frustrating it can be.

      As I understand it, that’s a pretty common error seen with OpenVPN, and it usually boils down to some issue with the configuration. I’d recommend that you double check that both your server and client configuration files were updated correctly and that the settings within them align. If that doesn’t point to the source of the issue, I’d then recommend that you look into the potential causes outlined on the OpenVPN FAQ.

      Great writing!!! worked flawlessly.

      Thanks so much

      The guide works great, now I have a working OpenVPN server on an EC2. The only thing I can’t get going is the web interfcae (Admin UI). I’ve opened ports 443 and 943 to TCP traffic yet nether https://VPN_IP:943/admin nor https://VPN_IP/admin load.

      how to set up the CA to be on the same server as the openvpn server? Thank you!

      I have problem: ./easyrsa gen-req client2 nopass -bash: ./easyrsa: No such file or directory

      After I followed the tutorial I ended up with VPN that doesn’t work. In my case tun0 is 10.8.0.1, two clients are 10.8.0.6 and 10.8.0.10. Clients are windows10 machines, OpenVPN runs on ubuntu 18 LTS. I disabled firewall on both Windows clients. The reason is the result is bad is because these two clients cannot communicate with each other: I can ping any client from the machine that runs OpenVPN server, and I can ping server from these machines. However, these two windows10 machines cannot ping each other as if there is no route between these two.

      This is an amazing tutorial! I’m so glad you put this together Mark. You saved me hours of trying to figure this out on my own. The level of detail was excellent and enabled me to setup my first VPN server without any issues whatsoever.

      The only detail I had to lookup was what DNS servers to use with the server configuration. Cloudfare seems to be a good one; 1.1.1.1 and 1.0.0.1 . They are super fast.

      I just started messing with Linux a couple days ago. This was my first challenge. To my astonishment, it actually works! First try! Not that I actually understood much of any of the steps, but at least I can follow instructions. And it’s a testament to the quality of the instructions themselves.

      Can you please make it obvious that you are asking us at Step 4 to generate the client certificate on the VPN server and not on the CA server?

      It is not made obvious by you until after we are asked to run the gen-req command and then scp the files over to the CA server.

      Great howto! Just one minor error I’d came across was that my HMAC Authentication failed when I tried to start the VPN (like described here: https://askubuntu.com/questions/594868/openvpn-hmac-authentication-failure-no-matter-what-i-do#611278).

      I solved that by adding these directives to the server.conf:

      mode server
      tls-server
      

      and than to the base.conf:

      tls-client
      

      Don’t know if this is only related to my server (LXC with tun/tap)?

      Hi!

      I’m testing this scenario with an Ubuntu client. OpenVPN server is correctly creating tun0 in 10.8.0.1 -10.8.0.2 peer. However Ubuntu client is creating an tun0 interfacein 10.8.0.10 - 10.8.0.9.

      tun0: flags=4305&lt;UP,POINTOPOINT,RUNNING,NOARP,MULTICAST&gt;  mtu 1500
              inet 10.8.0.10  netmask 255.255.255.255  destination 10.8.0.9
              inet6 fe80::ed96:59be:600c:c59b  prefixlen 64  scopeid 0x20&lt;link&gt;
              unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 100
      
      Server status is:
       openvpn@server.service - OpenVPN connection to server
         Loaded: loaded (/lib/systemd/system/openvpn@.service; indirect; vendor preset: enabled)
         Active: active (running) since Thu 2020-01-23 10:38:39 UTC; 14min ago
           Docs: man:openvpn(8)
                 https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage
                 https://community.openvpn.net/openvpn/wiki/HOWTO
       Main PID: 903 (openvpn)
         Status: "Initialization Sequence Completed"
          Tasks: 1 (limit: 2318)
         CGroup: /system.slice/system-openvpn.slice/openvpn@server.service
                 └─903 /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/openvp
      
      Jan 23 10:47:21 servervpn ovpn-server[903]: 192.168.56.103:36897 [client1] Peer Connection Initiated with [AF_INET]192.168.56.103:36897
      Jan 23 10:47:21 servervpn ovpn-server[903]: MULTI: new connection by client 'client1' will cause previous active sessions by this client to be dropped.  Remember to use the --duplicate-cn o
      Jan 23 10:47:21 servervpn ovpn-server[903]: MULTI_sva: pool returned IPv4=10.8.0.10, IPv6=(Not enabled)
      Jan 23 10:47:21 servervpn ovpn-server[903]: MULTI: Learn: 10.8.0.10 -> client1/192.168.56.103:36897
      Jan 23 10:47:21 servervpn ovpn-server[903]: MULTI: primary virtual IP for client1/192.168.56.103:36897: 10.8.0.10
      Jan 23 10:47:22 servervpn ovpn-server[903]: client1/192.168.56.103:36897 PUSH: Received control message: 'PUSH_REQUEST'
      Jan 23 10:47:22 servervpn ovpn-server[903]: client1/192.168.56.103:36897 SENT CONTROL [client1]: 'PUSH_REPLY,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.10 10.8.0
      Jan 23 10:47:22 servervpn ovpn-server[903]: client1/192.168.56.103:36897 Data Channel: using negotiated cipher 'AES-256-GCM'
      Jan 23 10:47:22 servervpn ovpn-server[903]: client1/192.168.56.103:36897 Outgoing Data Channel: Cipher 'AES-256-GCM' initialized with 256 bit key
      Jan 23 10:47:22 servervpn ovpn-server[903]: client1/192.168.56.103:36897 Incoming Data Channel: Cipher 'AES-256-GCM' initialized with 256 bit key
      

      The client trace when running openvpn with client1.ovpn config file is the following one:

      sudo openvpn --config client1.ovpn
      
      Thu Jan 23 11:55:13 2020 OpenVPN 2.4.4 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on May 14 2019
      Thu Jan 23 11:55:13 2020 library versions: OpenSSL 1.1.1  11 Sep 2018, LZO 2.08
      Thu Jan 23 11:55:13 2020 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
      Thu Jan 23 11:55:13 2020 Outgoing Control Channel Authentication: Using 256 bit message hash &apos;SHA256&apos; for HMAC authentication
      Thu Jan 23 11:55:13 2020 Incoming Control Channel Authentication: Using 256 bit message hash &apos;SHA256&apos; for HMAC authentication
      Thu Jan 23 11:55:13 2020 TCP/UDP: Preserving recently used remote address: [AF_INET]192.168.56.101:1194
      Thu Jan 23 11:55:13 2020 Socket Buffers: R=[212992-&gt;212992] S=[212992-&gt;212992]
      Thu Jan 23 11:55:13 2020 UDP link local: (not bound)
      Thu Jan 23 11:55:13 2020 UDP link remote: [AF_INET]192.168.56.101:1194
      Thu Jan 23 11:55:13 2020 TLS: Initial packet from [AF_INET]192.168.56.101:1194, sid=82424976 62272596
      Thu Jan 23 11:55:13 2020 VERIFY OK: depth=1, CN=serverca
      Thu Jan 23 11:55:13 2020 VERIFY KU OK
      Thu Jan 23 11:55:13 2020 Validating certificate extended key usage
      Thu Jan 23 11:55:13 2020 ++ Certificate has EKU (str) TLS Web Server Authentication, expects TLS Web Server Authentication
      Thu Jan 23 11:55:13 2020 VERIFY EKU OK
      Thu Jan 23 11:55:13 2020 VERIFY OK: depth=0, CN=servervpn
      Thu Jan 23 11:55:13 2020 Control Channel: TLSv1.3, cipher TLSv1.3 TLS_AES_256_GCM_SHA384, 2048 bit RSA
      Thu Jan 23 11:55:13 2020 [servervpn] Peer Connection Initiated with [AF_INET]192.168.56.101:1194
      Thu Jan 23 11:55:14 2020 SENT CONTROL [servervpn]: &apos;PUSH_REQUEST&apos; (status=1)
      Thu Jan 23 11:55:14 2020 PUSH: Received control message: &apos;PUSH_REPLY,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.10 10.8.0.9,peer-id 0,cipher AES-256-GCM&apos;
      Thu Jan 23 11:55:14 2020 OPTIONS IMPORT: timers and/or timeouts modified
      Thu Jan 23 11:55:14 2020 OPTIONS IMPORT: --ifconfig/up options modified
      Thu Jan 23 11:55:14 2020 OPTIONS IMPORT: route options modified
      Thu Jan 23 11:55:14 2020 OPTIONS IMPORT: peer-id set
      Thu Jan 23 11:55:14 2020 OPTIONS IMPORT: adjusting link_mtu to 1624
      Thu Jan 23 11:55:14 2020 OPTIONS IMPORT: data channel crypto options modified
      Thu Jan 23 11:55:14 2020 Data Channel: using negotiated cipher &apos;AES-256-GCM&apos;
      Thu Jan 23 11:55:14 2020 Outgoing Data Channel: Cipher &apos;AES-256-GCM&apos; initialized with 256 bit key
      Thu Jan 23 11:55:14 2020 Incoming Data Channel: Cipher &apos;AES-256-GCM&apos; initialized with 256 bit key
      Thu Jan 23 11:55:14 2020 ROUTE: default_gateway=UNDEF
      Thu Jan 23 11:55:14 2020 TUN/TAP device tun0 opened
      Thu Jan 23 11:55:14 2020 TUN/TAP TX queue length set to 100
      Thu Jan 23 11:55:14 2020 do_ifconfig, tt-&gt;did_ifconfig_ipv6_setup=0
      Thu Jan 23 11:55:14 2020 /sbin/ip link set dev tun0 up mtu 1500
      Thu Jan 23 11:55:14 2020 /sbin/ip addr add dev tun0 local 10.8.0.10 peer 10.8.0.9
      Thu Jan 23 11:55:14 2020 /etc/openvpn/update-resolv-conf tun0 1500 1552 10.8.0.10 10.8.0.9 init
      Thu Jan 23 11:55:14 2020 /sbin/ip route add 10.8.0.1/32 via 10.8.0.9
      Thu Jan 23 11:55:14 2020 WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this
      Thu Jan 23 11:55:14 2020 Initialization Sequence Completed
      

      And the client route in client is the following one:

      route
      
      Tabla de rutas IP del núcleo
      Destino         Pasarela        Genmask         Indic Métric Ref    Uso Interfaz
      10.8.0.1        10.8.0.9        255.255.255.255 UGH   0      0        0 tun0
      10.8.0.9        0.0.0.0         255.255.255.255 UH    0      0        0 tun0
      link-local      0.0.0.0         255.255.0.0     U     1000   0        0 enp0s3
      192.168.56.0    0.0.0.0         255.255.255.0   U     100    0        0 enp0s3
      

      I have the impression client1 is creating a tunnel around the server tunnel.

      Might someone point me to what I have done wrong?

      Thank you in advance!

      I just wanted to say that this was a great write-up and tutorial. It took me awhile to get through it but was well worth it in the end.

      This was a great tutorial. However, when trying to connect, it failed. I think the certificate has an error, but I followed all the steps. Please help. Thanks! Here is a screenshot: https://drive.google.com/file/d/1Kw69juBOpPxLF7l0tckrKj1Sz0s_NUl8/view?usp=sharing

      hello @tech128ca I am also getting the same error. Did you got the solution regarding the same? Thank you.

      Note that resolvconf is not installed by default in Ubuntu 18.04. (Or it somehow got removed for me.) Thus a Linux client will not be able to pull any DNS config until the client runs sudo apt-get install resolvconf. Until then, the /etc/openvpn/update-resolv-conf script fails silently.

      Actually, this does not fix things. It seems that update-resolv-conf runs as user nobody, and somehow lacks permission to delete the resolvconf rules that get added. In particular, the line /sbin/resolvconf -d tun0.openvpn fails with rm: cannot remove 'tun0.openvpn': Permission denied. Seems to be a bit of a mess.

      G R E A T ! T H A N K - -Y O U - - F R O M - - I T A L Y .

      The best (an only) complete tutorial.

      Please check in section 4

          ssh sammy@your_CA_ip
          cd EasyRSA-3.0.4/
          ./easyrsa import-req /tmp/client1.req client1
      

      Maybe the line I highlighted is redundant.

      Bye.

      Great tutorial, got me up and running and way nicer than my little ssh tunnel setup I had going. Thanks!

      One thing though, perhaps I missed something but once I connected with the VPN I had to manually set a route on my Windows PC to get it to see the network behind my OpenVPN server, did I do something wrong? It works with the added route but I’m sure there is a way to configure the server to supply it.

      Nevermind, I just had to uncomment the push route in the /etc/openvpn/server.conf and restart the service.

      In my case:

      push “route 192.168.0.0 255.255.255.0”

      Of course I don’t have a conflict since my local network is 192.168.1.0/24

      Amazing stuff. Perfectly detailed. This helped me so much. Thanks a lot!

      Thank you for the amazing guide!

      For proper DNS resolution in a windows domain environment this has to be added to (I think, haven’t tested either or) both the client and server configs: push “dhcp-option DOMAIN”

      I have walked through this tutorial 6-8 times. I have 2 VPSs one with VPN server & one with CA. Followed everything. I export the client1.ovpn but it refuses to connect. Any suggestions?

      When I run:

      sudo openvpn --config client1.ovpn
      

      This is the output:

      Thu Sep 17 16:39:15 2020 OpenVPN 2.4.7 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Sep  5 2019
      Thu Sep 17 16:39:15 2020 library versions: OpenSSL 1.1.1f  31 Mar 2020, LZO 2.10
      Thu Sep 17 16:39:15 2020 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
      Thu Sep 17 16:39:15 2020 Outgoing Control Channel Authentication: Using 256 bit message hash 'SHA256' for HMAC authentication
      Thu Sep 17 16:39:15 2020 Incoming Control Channel Authentication: Using 256 bit message hash 'SHA256' for HMAC authentication
      Thu Sep 17 16:39:15 2020 TCP/UDP: Preserving recently used remote address: [AF_INET]<VPN host remote IP>:1194
      Thu Sep 17 16:39:15 2020 Socket Buffers: R=[212992->212992] S=[212992->212992]
      Thu Sep 17 16:39:15 2020 UDP link local: (not bound)
      Thu Sep 17 16:39:15 2020 UDP link remote: [AF_INET]<VPN host remote IP>:1194
      Thu Sep 17 16:39:15 2020 NOTE: UID/GID downgrade will be delayed because of --client, --pull, or --up-delay
      Thu Sep 17 16:40:16 2020 TLS Error: TLS key negotiation failed to occur within 60 seconds (check your network connectivity)
      Thu Sep 17 16:40:16 2020 TLS Error: TLS handshake failed
      ...
      

      I can ssh into the host IP fine.

      Mark Drake
      DigitalOcean Employee
      DigitalOcean Employee badge
      September 21, 2020

      Hello @kurdtpage,

      Thanks for your comment! I just completed the tutorial as it’s written and wasn’t able to replicate that error. That said, I have encountered similar errors in the past, and I know they’re fairly common in OpenVPN.

      Because I couldn’t replicate that error, it’s difficult to say what could be causing the issue on your end. The OpenVPN website provides this page which offers some suggestions for how to resolve TLS Error: TLS key negotiation failed to occur within 60 seconds errors. I’d recommend that you review and test out those suggestions, in addition to going back and ensuring that you’ve correctly updated all the necessary files as described in this tutorial.

      Good day!

      Nice guide sir, I have successfully installed my own VPN server on digital ocean droplet.

      I just have a question. I can’t connect to my VPN server when my client is using http proxy. I made a proxy using squid on another digital ocean droplet. It says 503 Service Unavailable. Also when I try to curl my VPN server like so:

      curl -I -x myproxy.com:80 http://myvpnserver.com:1194

      It also returns 503 Service Unavailable. Even without the port 1194 still the same return.

      Where should I make changes? On my VPN server? My VPN server’s iptables? My proxy server’s squid proxy conf?

      Please help.

      Hi,

      It is a great tutorial.

      I just want to ask one question that what if OpenVPN service goes down for whatever reason then what will happen to the machine? Will it be at all accessible from outside? If not then how one will get on the machine to fix the service?

      Mark Drake
      DigitalOcean Employee
      DigitalOcean Employee badge
      November 12, 2020

      Hello @raheelsiddiqui, and thank you for your question.

      If the OpenVPN service fails or stops running, the server on which it was running should still be accessible over SSH unless there’s an underlying issue with the server itself.

      Hello, We’ve configured two servers for VPN and both are from the digital ocean as prefered in this blog. After that, we downloaded the ovpn file which got connected but our IP address remained the same and the blocked websites didn’t open. Can you guys please help us out?

      I am stuck in Step 9 with the following error: ./make_config.sh: line 9: /root/client-configs/files/client1.ovpn: No such file or directory

      What should I do?

      Mark Drake
      DigitalOcean Employee
      DigitalOcean Employee badge
      January 8, 2021

      Hello @kelvin911, and thank you for your question.

      I just went through this tutorial and was able to complete it as written, including the part you reference in Step 9 where one creates the client1.ovpn file with the make_config.sh script. However, I was able to replicate that error message by logging in as the root user and trying to run the script.

      This guide was written with the intention that all the commands shown be completed as a non-root user with sudo privileges. If you’re still running into this error, I’d recommend you make sure your logged in as your non-root user before attempting to run the script. Also, it may help to double check that you’ve set the permissions on the client-configs directory correctly. You can do so by running this command from Step 4:

      1. chmod -R 700 ~/client-configs

      I hope that helps!

      I have to sign up for this community because of this excellent tutorial. It’s very detailed and also provides a clear explanation. Thank you so much.

      Great guide, thanks for the info.

      I’m running ubuntu server for raspberry pi on a pi 4 8gb. I ran into an issue when re-enabling it after changing /etc/ufw/before.rules. I got around the issue by adding the before.rules edits at the end of the file after “COMMIT.”

      Hi, I just finished step 7 and my connection to OpenVPN Server on DO is dropped and I am no longer able to reconnect to my droplet anymore. Is there any possible cause and solution? I only finished Initial setup & VNC setup before starting working on installing OpenVPN.

      When I check status of VNC, there is one error:

       Loaded: loaded (/etc/systemd/system/vncserver@.service; indirect; vendor preset: enabled)
         Active: active (running) since Sun 2021-06-06 10:36:34 UTC; 6min ago
        Process: 949 ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 :1 (code=exited, status=0/SUCCESS)
        Process: 896 ExecStartPre=/usr/bin/vncserver -kill :1 > /dev/null 2>&1 (code=exited, status=2)
      
      

      This steps are very useful! it works for me! Thank you so much Mark!

      Having issue importing the config file in the android or pc OpenVpn Connect app.

      “ailed to parse profile: ca.crt, client.crt, client.key, ta.key” That’s the error message. please help

      hu Aug 19 08:29:03 2021 DEPRECATED OPTION: --cipher set to ‘AES-256-CBC’ but missing in --data-ciphers (AES-256-GCM:AES-128-GCM). Future OpenVPN version will ignore --cipher for cipher negotiations. Add ‘AES-256-CBC’ to --data-ciphers or change --cipher ‘AES-256-CBC’ to --data-ciphers-fallback ‘AES-256-CBC’ to silence this warning.

      Hello that is my error when my client try to connect using .ovpn in windows and it is now working… then i tried to change CBC to GCM then it’s still now working…

      Is there any limit to the number of devices that can connect simultaneously?

      I’m getting an TCP_CLIENT link local: (not bound) error here. Don’t know what the problem is. I have checked my files a million times so if there is any problems but there were none. Thanks in advance.

      This is an excellent tutorial. Though I would like to add one thing. if you want your VPN clients to communicate with each other, it will not be done by default. You have to uncomment the ‘client-to-client’ portion in the /etc/openvpn/server.conf file.

      If you do not uncomment this line, then the VPN clients would not be able to even ping each other.

      I was facing this problem, as I wanted my VPN clients to communicate with each other. Leaving this comment, as it might be useful to someone in the future.

      Try DigitalOcean for free

      Click below to sign up and get $200 of credit to try our products over 60 days!

      Sign up

      Join the Tech Talk
      Success! Thank you! Please check your email for further details.

      Please complete your information!

      Become a contributor for community

      Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

      DigitalOcean Documentation

      Full documentation for every DigitalOcean product.

      Resources for startups and SMBs

      The Wave has everything you need to know about building a business, from raising funding to marketing your product.

      Get our newsletter

      Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

      New accounts only. By submitting your email you agree to our Privacy Policy

      The developer cloud

      Scale up as you grow — whether you're running one virtual machine or ten thousand.

      Get started for free

      Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

      *This promotional offer applies to new accounts only.