How to set up OpenVPN server on Ubuntu 22.04

“A Virtual Private Network, or VPN, allows you to extend a private network across public networks. It improves your online security; to the example, if you are in a hotel and use the hotel’s internet connection for your business, there is a high probability that your data will be breached. VPN connections are private and encrypted, preventing unauthenticated access to your connection. Today in this tutorial we will go through all the steps required to set up OpenVPN Server on Ubuntu 22.04.”


OpenVPN is an open source application that is mainly used to access remote websites, establish secure connections and improve security through encryption, authentication and of course certification using the OpenSSL library. We will now set up OpenVPN on Ubuntu 22.04.

Step 1: Update the system packages

sudo apt get update && sudo apt-get upgrade

And it automatically updates your system’s packages.

Step 2: Install OpenVPN

sudo suitable -y To install openvpn

Now you have to wait for a while and when you’re done you can go to step 3.

Step 3 Generate a static key to use for VPN tunnel encryption and start the VPN server

openvpn –genkey –Secret static-OpenVPN.key
sudo openvpn –dev do –ifconfig –Cipher AES256-CBC –Secret static-OpenVPN.key &

Note: You may have noticed the “&” at the end of the command above, and it’s meant to help you keep the OpenVPN process in the background so you don’t have to keep the terminal open.

Step 4: Check if you come true

Just type the following command and you will do it do0 with an IP address of

IP do a show0

The output would be like this

Now we need to verify that UDP port 1194 is open for connections using the following command

net stat -anu | grep 1194

And this would produce an output like this

Step 5: Configure Firewall

Use the following command to configure the firewall

$ sudo ufw allowed from anyone to any port 1194 protoudp

And you will see the following output

The OpenVPN server is now able to receive incoming connections.

Now how will you connect the OpenVPN server from a remote client? Well, you need to follow the steps below.

Step 1: Install OpenVPN

sudo suitable -y To install openvpn

Step 2: Transfer the OpenVPN static key file from the OpenVPN server to the client

First we need to transfer the file from the server to the client using a secure method of your choice, but we’ll use that SCP command like this

scp user@Linux hint:/hometown/user/static-OpenVPN.key

Note: This command must be issued from the client side and use your username.

Step 3: Establishing a VPN tunnel to the server

With the following command we can establish a VPN tunnel to the server, but You need to change the IP address according to the server you are connecting to

$ sudo openvpn –Remote control YOUR-OPENVPN-SERVER-IP-OR-HOST –dev do –ifconfig –Cipher AES256-CBC –Secret static-OpenVPN.key &

Have you noticed the AES-256-CBC cipher? Well, this is the most secure encryption and decryption of the data chain.

Step 4: Test if the connection was successful

When you’re done with step 3, you should be able to see the following message if the connection was successful.

Now let’s confirm the successful connection by pinging a host on the remote server using the following command

Ring -c 1

We’ll see something like that, but don’t worry if it’s different on your side


In this tutorial, we’ve gone through all the steps needed to receive incoming connections using OpenVPN, and we’ve also learned how to connect to an OpenVPN server from a remote client on Ubuntu. If you encounter a bug or issue please contact us as we are always happy to help our community.

Related Posts