Setup and connect to VPN using OpenVPN Client On Ubuntu

Overview

This tutorial only about openvpn client, not the server. I’ll show you how to connect to a VPN using openvpn3. What you need is a .opvn file and the username and password to login to the vpn server.

Install OpenVPN3 on ubuntu

There is an easy to follow guide here you follow to get openvpn3 installed: https://openvpn.net/cloud-docs/tutorials/configuration-tutorials/connectors/operating-systems/linux/tutorial–learn-to-install-and-control-the-openvpn-3-client.html

Configure and connect to openvpn

Now you have openvpn3 client installed. Here are the steps you need to import and use it.

Import the config

openvpn3 config-import --config path_to.ovpn --name "my-vpn" --persistent

Allow compression

openvpn3 config-manage --config my-vpn --allow-compression yes

That’s it! now your connection is ready.

In order to connect to the VPN, use the following command:

openvpn3 session-start --config my-vpn

You will be prompted to enter your username and password. Enter the credentials to get connected.

Remember password

By default, you are asked every time you login. If you feel this is tedious, there is a way.

First, create a plain text file with your username and password.

username
password

Store it somewhere and run the following command

chmod 600 path_to_your_credentials_file

Now, open the .opvn file and point to the credentials file like this:

auth-user-pass path_to_your_credentials_file

Now you need to delete the current config (if you want to use the same name)

openvpn3 config-remove --config "my-vpn"

Then you run the import again.

The next time you connect, you will not have to enter the username and password.

Useful commands

Here are some useful commands

# list config, this will also show the config names and path. When you have duplicate names
# and you want to remove a particular config, you need to use the path
openvpn3 configs-list --verbose

# Remove config by name


# remove config by path
openvpn3 config-remove --path path_to_your_config # use the configs-list above

# Connect
openvpn3 session-start --config config-name 

# Disconnect
openvpn3 session-manage --config config-name --disconnect

Tips

if typing openvpn3 every time is tedious, create an alias in your .bashrc or .zshrc to avoid typing

alias ov="openvpn3"

Leave a Comment