I had a daemon starting with my own self-hosted vpn that worked fine with:

sudo openvpn --config /home/philip/open_vpn/client1.ovpn

Now that I changed to a paid VPN service the above works but requires me to manually enter my credentials each time. This means my auto-start breaks.

Looking at the GUI for network manager it seems I can make any individual network auto-connect to the vpn, but unknown networks are the most important time for me to use vpn.

How can I get the auto-vpn to work without entering my email and password every time?


Here is how I got it working. In my folder with all my vpn ovpn files I create a file called auth.txt. Which contained the following, substituted for my actual credentials:


I then opened up the ovpn file I wanted to use, and found the line with auth-user-pass I modifying it to look like this, replace path with full path of your auth.txt file:

auth-user-pass /home/philip/open_vpn/auth.txt

I then made a bash script called start_vpn.sh which looks like:

#!/usr/bin/env bash
sudo openvpn --config /home/philip/open_vpn/nord/ca24.nordvpn.com.udp1194.ovpn

I then create a systemd startup script at /etc/systemd/system/start-openvpn.service which looks like:



I then enable the systemd job with:

systemctl enable start-openvpn.service


If you have 100s of ovpn files like me you may want to update the line in all these files at once. Here is the sed command I used in the folder with my ovpn file, you will nedd to update to reflect your system:

sed -i *nordvpn* -e 's/auth-user-pass/auth-user-pass \/home\/philip\/open_vpn\/auth.txt/g'

The first, You edit file vim /etc/default/openvpn and uncomment the AUTOSTART="all" line. Save and Reboot your system.

enter image description here

And you can read more link: Start Openvpn client automatically at boot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.