
OpenVPN is a full-featured, open-source secure socket layer (SSL) virtual private network (VPN) that offers a broad range and rapid development of features that allow you to access the Internet safely and securely through your private server. In this guide, we install OpenVPN on a Ubuntu 20.04 server.
First, update your server, and install OpenVPN from default Ubuntu sources.
Since OpenVPN is an SSL VPN, it uses certificates to encrypt traffic between the server and connected clients. So, we need to install the easy-rsa hosted certificate authority to create and sign new certificates on the server.
We need to utilize the easy-rsa template to create our OpenVPN server's Certificate Authority by copying it to a new directory.
Enter the created directory
Now, open the file named vars through nano or any other editor.
Locate the following entries, uncomment them by removing the # sign, and enter your details.
Particularly, you should enter your desired country, province, city, company, email, and department. After editing, your file should now look similar to the one below.
Save and close the file.
Next, within the openvpn-ca directory resides a script easyrsa that lets you perform a series of tasks and commands for building the certificate authority. Execute the script with the argument inti-pki to ready public key infrastructure on the server.
Build the CA to create two important files (ca.crt and ca.key) that make up an SSL certificate.
During the build process, you will be asked to enter a common name for your certificate authority, enter a simple name or click enter for a default name.
Now that a CA has been created, you need to build a server certificate and key pair. To do so, run the command below with a custom name for your server. In this case, we use vpnserver. Replace it with a desired simpler name since it will be required for reference.
The command will create a new private server key and certificate request file. Now, create a strong Diffie-Hellman key that will be used during the key exchange process.
This may take a few minutes to complete. Once ready, create an HMAC signature to strengthen the TLS certificate integrity verification capabilities:
Finally, copy the created vpnserver, dh, and hmac keys to the OpenVPN directory.
Navigate back to the CA directory and run the easyrsa script with gen-req, and a simple name for your client.
Press enter to confirm the common name. If you wish to create a user protected with a password, remove the nopass option.
Now that we've created a certificate authority, we must configure the server. First, copy and extract the sample OpenVPN configuration file to the default directory.
Open the configuration file located at /etc/openvpn/server.conf and make some changes to it.
Uncomment the following lines:
Change the user directive to listen for a non-privileged user instead of root.
Now, ensure that OpenVPN is pointing to the right .crt and .key files. Then, change the entries depending on the VPN server name prescribed earlier in this guide.
Save and close the file.
Next, to allow connected clients to access the Internet through the OpenVPN server, we need to modify /etc/sysctl.conf
Uncomment the line:
Save and close the file, then apply the changes.
To provide internet access and properly direct traffic, we need to set up a Network Address Translation (NAT) rule with the following command.
Congratulations, you have successfully installed OpenVPN on your Ubuntu 20.04 server.
0 Comments
Be the first to comment and share your perspective with the community.