Use systemd
In order to configure OpenVPN to autostart using systemd, complete the following steps:
Run the command:
sudo nano /etc/default/openvpn
and uncomment, or remove, the “#” in front of
AUTOSTART="all"
then press Ctrl+O followed by Enter to save the changes and Ctrl+X to exit the text editor.
Copy the .ovpn file with the desired server location to the ‘/etc/openvpn’ folder:
sudo cp /location/whereYouDownloadedConfigfilesTo/confyg.ovpn /etc/openvpn/
Edit the .ovpn file you copied in the previous step and change the line ‘auth-user-pass’ to ‘auth-user-pass pass’:
sudo nano /etc/openvpn/confyg.ovpn
then press Ctrl+O followed by Enter to save the changes and Ctrl+X to exit the text editor.
In the ‘/etc/openvpn’ folder, create a text file called pass:
sudo nano /etc/openvpn/pass
and enter your VPN Account ID on the first line and VPN passwordon the 2nd line, then press Ctrl+O followed by Enter to save the changes and Ctrl+X to exit the text editor.
Change the permissions on the pass file to protect the credentials:
sudo chmod 400 /etc/openvpn/pass
Rename the .ovpn file to ‘client.conf’:
sudo mv /etc/openvpn/confyg.ovpn /etc/openvpn/client.conf
Enable the Openvpn@ service with the following command:
sudo systemctl enable [email protected]
Reload the daemons:
sudo systemctl daemon-reload
Start the OpenVPN service:
sudo service openvpn@client start
Reboot and test if it is working by checking the external IP.
Adapted from: https://www.ivpn.net/knowledgebase/linux/linux-autostart-openvpn-in-systemd-ubuntu/
Hope this helps