How to Install OpenVPN on Ubuntu 20.04 / 22.04 (Step by Step). In this post, we introduce OpenVPN protocol, its working principle, advantages then show you how to install OpenVPN server on Ubuntu.
OpenVPN is the VPN encryption protocol with the largest user base. One of the first VPN encryption technologies started in 2001. The software is considered as the best security and versatility solution due to its connectivity with Windows, macOS, Android and Linux.
Firstly, OpenVPN is currently one of the most reliable protocols. It functions as both software and a VPN protocol. Also, it uses various security measures to offer a site to site or secure point to point network connection. Nowadays, there are plenty of VPN providers and consumers who are using this protocol.
Moreover, OpenVPN was created by James Yohan and published to the general public in 2001. Choose a variety of ports and encryption methods with it. What is more, it also enables you to use it for other projects or check its source code for problems.
All in all, this protocol helps in managing client server connections perfectly. Creates a very secure tunnel for the transfer of data between your device and the VPN server and conversely. Some of the platforms that use OpenVPN are macOS, iOS, Windows, Linux, Android, and routers.
A VPN connection protects your internet connection when functioning from a distance (e.g., hotel, airport, or even a different country). Basically, a VPN transmits all of your network traffic over an encrypted tunnel. Routing network traffic hides your IP address when accessing the internet by substituting it with the location and an IP address from the VPN server, which misrepresents the location. Besides, a VPN connection additionally protects against outside attacks.
Let’s examine the advantages that help OpenVPN to gain a user base among VPN providers.
Better Security
Certainly, OpenVPN uses peer authentication and pre shared keys, among other security protocols, to secure communication. Further, the network has maximum protection and security from Man in the Middle attacks by using OpenSSL in combination with HMAC packet authentication.
Reliability
If OpenVPN disconnects for some reason, the network comes to a halt so that it can be fixed or configured. As an outcome, it is essential to be sure that there are no information losses or communications failures.
Cost
Most of the time, OpenVPN is downloaded for free. Some platforms provide it for free of costs like MacOS, Linux, Android, and iOS. Additionally, you also use OpenVPN to have a free connection to a VPN server. As a result, whenever VPN connections are received from a certain server, OpenVPN gives access for free. This implies that OpenVPN is convenient and cost effective.
Community Support
Chiefly, OpenVPN has support from the global community as it is an open source solution. Use almost any GNU GPL licensed software to support them. This is due to the source code’s ease of modification. Anyone who needs to use our VPN network benefits from it.
Firewall Compatibility
Since OpenVPN is accessible on the port that facilitates TCP or UDP, significant security limitations to overcome. Network imposed firewalls cannot obstruct connections to OpenVPN, even if they exist.
Platform support
Regardless of the operating system, a wide range of devices and platforms can support OpenVPN. These platforms are Mac OS, Android, and iOS. Therefore, it is not only preferred by seasoned users but also suitable for newcomers.
We have reached the main part of the article How to Install OpenVPN on Ubuntu 20.04 / 22.04.
Step 3 - Installing Easy-RSA and Creating PKI for OpenVPN
Next, you need to install Easy-RSApublic key infrastructure (PKI) management tool on your server. By default, it is available in the Ubuntu default repository. Please install it using the following command.
apt install easy-rsa -y
Once installed, navigate to your Easy-RSA directory and create a vars file to create OpenVPN server’s private key and certificate.
If everything is fine, you will get the following output.
pki/issued/cloudinfra-server.crt: OK
Next, you will also need to generate Diffie-Hellman key to use for the key exchange. YGenerate it with the following command.
./easyrsa gen-dh
You will see the following output.
Note: using Easy-RSA configuration from: /usr/share/easy-rsa/vars
Using SSL: openssl OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)
Generating DH parameters, 2048 bit long safe prime
.++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*++*
DH parameters of size 2048 created at /usr/share/easy-rsa/pki/dh.pem
Finally, copy all the certificate and key file to the OpenVPN server directory.
At this point, your OpenVPN certificates are ready to use. Now, you need to create certificate and key file for the client. First, build the client key using the following command.
./easyrsa gen-req client nopass
You should see the following screen.
Then, sign the key using the following command.
./easyrsa sign-req client client
You should see the following screen.
Finally, copy all client key and certificate file to the client directory.
Next, you need to create an OpenVPN configuration file and define the port, and path of all your generated certificate and key. Create a configuration file using the following command.
nano /etc/openvpn/server.conf
Add the following configurations:
port 1194
proto udp
dev tun
ca /etc/openvpn/server/ca.crt
cert /etc/openvpn/server/cloudinfra-server.crt
key /etc/openvpn/server/cloudinfra-server.key
dh /etc/openvpn/server/dh.pem
server 10.8.0.0 255.255.255.0
push "redirect-gateway def1"
push "dhcp-option DNS 208.67.222.222"
push "dhcp-option DNS 208.67.220.220"
duplicate-cn
cipher AES-256-GCM
auth SHA256
auth-nocache
keepalive 20 60
persist-key
persist-tun
compress lz4
daemon
user nobody
group nogroup
log-append /var/log/openvpn.log
verb 3
explicit-exit-notify 0
Save and close the file when you are done. Then, start the OpenVPN service and enable it to start at system reboot.
This section explains how to install OpenVPN on client system and connect it to the OpenVPN server.
First, log into the client machine and install the OpenVPN package using the following command.
apt install openvpn -y
After the successful installation, you need to copy all client’s certificate, key and configuration file to the client machine. You copy all of them with the following command.
How to Install OpenVPN on Ubuntu 20.04 / 22.04 (Step by Step) Conclusion
We hope you can now implement OpenVPN in your organization to provide secure your network. Users use OpenVPN, an open VPN protocol, and a VPN client software to execute secure VPN connections. Truly, VPN providers offer this protocol because of its use of the OpenSSL library, 256 bit encryption and cross platform compatibility. Generally, you should choose a VPN service that provides access to OpenVPN connections and other VPN protocols.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.