How to Use VPS to Set Up a OpenVPN Server: Step-by-Step Guide

Virtual Private Servers (VPS) offer a flexible and cost-effective way to set up a Virtual Private Network (VPN). A VPN can provide secure, encrypted internet connections, protect your online privacy, and allow you to bypass geo-restrictions. Setting up your VPN on a VPS ensures that you have full control over your server and your data. Here’s a detailed step-by-step guide to help you set up a VPN server using a VPS.

Why Use a VPS for Your VPN?

Before we dive into the steps, let’s understand why using a VPS for your VPN setup is beneficial:
1. Cost-Effectiveness: VPS services are generally more affordable than dedicated servers, making them an economical choice for hosting a VPN.
2. Full Control: With a VPS, you have root access to configure and manage your VPN server, ensuring full control over your data and security.
3. High Availability: Reputable VPS providers offer high uptime (often 99.9% or more), ensuring your VPN is always accessible.
4. Scalability: VPS plans can be easily upgraded to handle increased traffic or additional features.


To get started, you will need the following:
1. A VPS plan from a reliable provider. Ensure your VPS has at least 1GB of RAM for optimal performance.
2. Access to your VPS via SSH.
3. Basic knowledge of command-line interface (CLI) operations.

Step 1: Choose Your Operating System

Most VPN software is compatible with both Linux and Windows. However, Linux (especially Ubuntu) is often preferred for its robustness and ease of use in server environments. For this guide, we’ll use Ubuntu.
1. Access Your VPS: Use an SSH client to connect to your VPS.
ssh root@your-vps-ip
2. Update Your System: Ensure your VPS is up to date.
sudo apt-get update && sudo apt-get upgrade -y

Step 2: Install VPN Software

There are several VPN software options available, but OpenVPN is a popular choice due to its strong security features and open-source nature.
1. Install OpenVPN: Use the following command to install OpenVPN and Easy-RSA (for managing your encryption keys).
sudo apt-get install openvpn easy-rsa -y
2. Create the OpenVPN Directory: Set up a directory for OpenVPN.
make-cadir ~/openvpn-ca
cd ~/openvpn-ca

Step 3: Configure Easy-RSA

Easy-RSA is a tool that makes it easier to set up a Public Key Infrastructure (PKI) and generate SSL certificates for your VPN server.
1. Edit Variables: Edit the vars file to set your encryption parameters.
nano vars
Update the following fields to reflect your own information (e.g., country, city, email):
export KEY_CITY="SanFrancisco"
export KEY_ORG="YourOrganization"
export KEY_EMAIL=""
export KEY_OU="YourOrganizationalUnit"
2. Initialize the PKI:

Step 4: Generate Server and Client Certificates

1. Generate the Server Certificate and Key:
./build-key-server server
2. Generate Diffie-Hellman Parameters: This step ensures secure key exchange.
3. Generate the Client Certificate and Key:
./build-key client

Step 5: Configure OpenVPN

1. Copy the Sample Configuration File:
gunzip -c /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz > /etc/openvpn/server.conf
2. Edit the Configuration File:
nano /etc/openvpn/server.conf
Update the file with your details, ensuring you specify the paths to your certificates and keys.

Step 6: Enable IP Forwarding

1. Edit sysctl.conf:
nano /etc/sysctl.conf
Uncomment the line:
2. Apply the Changes:
sudo sysctl -p

Step 7: Set Up Firewall Rules

To ensure that your VPN traffic is properly routed and secure, set up the following firewall rules:
1. Configure UFW (Uncomplicated Firewall):
sudo ufw allow 1194/udp
sudo ufw allow OpenSSH
sudo ufw enable
2. Add NAT Rules:
sudo nano /etc/ufw/before.rules
3. Add the following lines after the *filter line:

Step 8: Start OpenVPN

1. Start the OpenVPN Service:
sudo systemctl start openvpn@server
2. Enable OpenVPN on Boot:
sudo systemctl enable openvpn@server

Step 9: Set Up Client Configuration

To connect your devices to the VPN, you’ll need to configure client settings.
1. Create a Configuration File for the Client:
nano client.ovpn
Include the following details:
dev tun
proto udp
remote your-vps-ip 1194
resolv-retry infinite
ca ca.crt
cert client.crt
key client.key
cipher AES-256-CBC
verb 3
2. Transfer Certificates to Client: Securely transfer the 'ca.crt', 'client.crt', and 'client.key' files to your client device.
3. Import Configuration: Use your VPN client to import the 'client.ovpn' file and connect.

Conclusion: VPS VPN Server

Setting up a VPN on a VPS provides a robust and private solution for secure internet browsing and data protection. By following the steps outlined in this guide, you can establish your VPN server with full control and flexibility. Remember to keep your VPN software and server up to date to maintain security and performance.

For more detailed and personalized support, VPSMart offers 24/7 assistance to ensure your VPN setup is smooth and effective. For more tips and in-depth guides on server management and VPN setups, explore our website and discover the range of services we offer to enhance your digital security and connectivity.