How to Auto Start OpenVPN Client on Ubuntu Bionic

Launch OpenVPN client as a daemon.

Here I assume you already have your own cert file - filename.ovpn. ๐Ÿ™‚
Modify its file extension to conf like so:

1mv filename.ovpn filename.conf 

Put your cert file inside /etc/openvpn directory like so:

1mv /path/to/filename.conf /etc/openvpn/

OpenVPN client service name would be [email protected].
Well, you might already know what to do to launch the service.

1sudo killall openvpn
2sudo systemctl enable --now [email protected]

Reload the system daemons.

1sudo systemctl daemon-reload

That's it. ๐Ÿ™‚

If you have username and password for the certfile, you need this step

Make a credential file like so:

1touch login.conf

Put this into the file:

1username
2password

Open your certfile to edit:

1sudo vim /etc/openvpn/filename.conf

Edit or add in this line:

1auth-user-pass /path/to/login.conf

If you want to launch it manually each time, I recommend a shell script

Write a shell script like so:

1#!/bin/bash
2sudo killall openvpn
3sudo openvpn --daemon --config /path/to/filename.ovpn

You can now use the script file whenever you need it, even on startup.
Happy networking! ๐Ÿ™‚

comments powered by Disqus