Prerequisites:
To perform the steps that we demonstrate in this guide, you will need the following components:
- A properly-configured Ubuntu system.
- A properly-configured Ubuntu cloud server (for OpenVPN server setup).
- Access to a non-root user with sudo permission on both systems. Learn more about managing sudo privilege.
OpenVPN Server Configuration
Manual installation and configuration of an OpenVPN server is a tedious work. To streamline the process, we will use a third-party installer script from GitHub: angristan/openvpn-install. The script supports a wide range of operating systems and architectures.
First, make sure that curl is installed:
We can now grab the installation script with the following curl command:
Next, we have to change the file permission so that we can execute the script. Use the following command to flag the script as an executable file:
Finally, run the script:
The script will ask for various info about the server, what features you want to enable/disable, and such. Then, it installs the necessary packages.
Once the installation process finishes, the script generates a client configuration file under the current working directory. This file is important to configure the clients that connect to this particular OpenVPN server.
If you’re an advanced user or system admin and require a finer control over the installation process, check out the manual setup process of OpenVPN server in Ubuntu 22.04.
OpenVPN Client Configuration
OpenVPN Client Package Installation
We now work on the client machine. The OpenVPN client software is directly available from the official Ubuntu repos.
First, update the APT package database:
Next, install the OpenVPN client:
OpenVPN Client Service
Upon installation, the client will register the openvpn service with systemd. Enable the service so that it starts at boot:
Then, start the service:
Check if the service is up and running:
Copying the OpenVPN Configuration File
We obtained an OpenVPN client configuration file from the server configuration. In this section, we will grab it from the server.
There are multiple ways that we can grab it from the server. One common method is to use the scp command. It’s basically the cp command but over SSH.
Copy the OpenVPN configuration file from the server to the current directory:
Configuring the VPN
With the configuration file, we can now use the Settings app to configure the VPN. Start the app from Activities.
From the Network tab, click the “+” icon after the VPN section.
From the new pop-up window, select “Import from file“.
Browse for the OpenVPN configuration file.
You’ll be presented with a window that contains various info about the VPN. Click “Add” to finalize the process.
Go back to the Network tab again. There should be a VPN entry under the VPN section.
Conclusion
In this guide, we demonstrated the installation and configuration of OpenVPN in Ubuntu. We showcased how to configure both an OpenVPN server and a client. Note that multiple clients can connect to the OpenVPN server with the configuration file.
Other than OpenVPN, there are also other methods of creating a VPN. For example, sshuttle can create a VPN over SSH. You can also configure a SOCKS proxy that acts as a VPN.
If you are interested in exposing your local web app to the internet, you can do so with the help of a reverse proxy like Nginx.
Happy computing!