Configure OpenVPN Client to Autostart on Ubuntu Linux

You’ve set up an OpenVPN server on pfSense or some other router/gateway and you have a remote server you’d like to connect back to the private network. Here’s how you do it.

First, let’s get it installed:

# sudo apt update && apt upgrade -y
# sudo apt install openvpn

Copy/paste your client configuration from your server place it in /etc/openvpn/nameofserver.config

# sudo nano /etc/openvpn/nameofserver.config

Change the line that reads auth-user-pass to auth-user-pass /etc/openvpn/pass

Let’s put your username and password in there:

# sudo nano /etc/openvpn/pass

Line 1 should be the username, line 2 should be the password.


Save it. Next, enable the service with your particular connection:

# systemctl enable openvpn@nameofserver
# systemctl start openvpn@nameofserver

You should be able to see a tunnel connection now:

# ip a

3: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 100
    inet brd scope global tun0
       valid_lft forever preferred_lft forever

All set. For setting up a server, see the following: