How to setup OpenVPN on Ubuntu Server

OpenVPN enables you to have complete control of your tunneled traffic because the server and client, both are under your surveillance.

OpenVPN is a free VPN service for secure remote access of your server/machine. It gives you the capability to encrypt your web traffic and route it securely. OpenVPN enables you to have complete control of your tunneled traffic because the server and client both are under your surveillance.

It will not only unblock all sites at a locally restricted internet connection ad-free but will also protect your traffic at an insecure open/public Wi-Fi.


Following are the few requirements for setting up OpenVPN;

  1. Ubuntu Server (preferably on any cloud)
  2. The server should have an Open Port to listen for incoming VPN connections
  3. Client Machine (preferably with Bash Environment)

Setting up OpenVPN

Connect to your Ubuntu Server using ssh or any other remote access protocol.

$ ssh ubuntu@[ip address of your Ec2 Instance] -i key.pem

Update your server. Run the following command;

$ sudo apt update && sudo apt upgrade -y

Now download the OpenVPN script with the following command;

$ wget -O

Download & Install OpenVPN Script
Download & Install OpenVPN Script

You have to run the script and provide the details it asks. Enter the following command;

$ sudo bash

It has automatically detected your private IP. Press Enter. It will prompt you to provide your public IP.

Entering Public IP
Entering Public IP

Now it will ask you to specify the protocol [TCP, UDP]. TCP is recommended. To choose TCP, Enter 2.

Choosing Protocol
Choosing Protocol

Now OpenVPN will ask you the listening port. Specify an open port.

Port Selection

You have to configure the DNS services you intend to use. Recommended DNS are Google & Open DNS.

DNS Selection
DNS Selection

Your OpenVPN server has successfully been configured. Now give a name to your client script. Press Enter & wait for the installation to complete.

Successful Installation
Successful Installation

Transfer this file to your client machine. There are a lot of ways to transfer files on the command line. We will be making python server on Ubuntu to transfer our file from server to client.

Switch to the directory where the client.ovpn file is stored. In this case, it is stored in /home/ubuntu/ directory.

$ cd /home/ubuntu/

Enter$ ls-la to confirm that file exists in the current directory.

Confirm File in Current Directory

To start a simple python server, enter the following commands.

In the case of python2, enter;

$ sudo python -m SimpleHTTPServer

In the case of Python3, enter;

$ sudo python3 -m http.server

Python Server
Python Server

Our server is listening on port 8000. Go to your client machine terminal and download the client.ovpn file by entering the following command;

$ wget

Downloading Client File

Remember to replace the Public IP, Port number, and the name of your file.

Now your file has successfully been transferred. You can initiate the connection by entering on your client machine;

$ sudo openvpn client.ovpn

To confirm your OpenVPN is running, go to Google & write “My IP.” If the IP is the same as the Public IP of your server, you have successfully configured the OpenVPN.


OpenVPN is a free service, contains no ads and encrypts our traffic hence bypassing URL & Content-based firewall/Proxy filters. It is easy to configure and gives us control of our tunneled traffic.

Zohaib Yousaf
My name is Zohaib Yousaf. I'm an Ethical Hacker & a Pen Tester. Python scripting and Bash automation is my hobby. My research work is in Anonymity. I have co-worked in development of few anonymity solutions which implemented different Cryptographic Algorithms.


Please enter your comment!
Please enter your name here





Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.
Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.

Getting Started with Linux Operating System

The Linux operating system brings forth a vibrant mix of features and security, making it the best alternative to macOS or Windows operating systems. In this post, we will give you a master guide on Getting started with Linux systems - taking you from a complete beginner to a level where you can begin testing the various Linux distributions available with much ease.

The 10 Best Linux Performance Monitoring Tools

Do you want to monitor the performance of your Linux system? Are you looking for some powerful performance monitoring tools to help you out? If you agree, it's your day as we have put together a detailed list of the ten best Linux performance monitoring tools.

Beaker Browser: A P2P web browser you must try

I think we can all agree on the fact that the web browser is an integral part of our Linux systems, or any computer system, for that matter. We have had several fulfilling options for browsing the web, like Firefox, Brave, Vivaldi, Tor, etc. and they have worked pretty well, but also pretty much in the same way, except for Tor, which is much better for anonymity.

5 Best ways to encrypt files in Linux

Privacy is something that almost all of us have concerns about. Many people switch over to Linux because of its better privacy features. In this time, where many people believe (quite rightly so) that privacy doesn't exist anymore, Linux provides a ray of hope. Distributions like Tails OS are specifically designed for that purpose.