I am trying to set OpenVPN to autostart on boot. With 18.04 Mate I have tried my usual put opvpn config into /etc/openvpn and then edit /etc/default/openvpn to connect all. This does not work, although it worked on 16.04.

I have looked into using systemd but I can't get it to work.

I have tried using network manager to connect on log in, as a compromise, this failed due to ethernet not auto connecting if a VPN is set to always be used.

So, in summary, what I want is:

My openvpn to automatically connect when I boot up.

Thanks for all and any help!



If you save your configuration as a MY_CONNECTION.conf file in your /etc/openvpn directory, you can do the following:

systemctl enable openvpn@MY_CONNECTION
systemctl start openvpn@MY_CONNECTION

where MY_CONNECTION is the same from MY_CONNECTION.conf.

So if you have multiple connections, you would have multiple systemctl calls.

systemctl enable openvpn@MY_CONNECTION1
systemctl start openvpn@MY_CONNECTION1
systemctl enable openvpn@MY_CONNECTION2
systemctl start openvpn@MY_CONNECTION2


  • Hi Matt. Thank you for your answer. systemctl enable openvpn@MY_CONNECTION systemctl start openvpn@MY_CONNECTION This works if I do it manually. It does not work on boot. My VPN does not automatically connect, for some reason. – xm88 May 18 '18 at 20:17
  • I think, perhaps, the issue is, when this command is called it request a password via a GUI dialogue box. – xm88 May 18 '18 at 20:19
  • So the line in /etc/default/openvpn that reads "WARNING: If you're running systemd the rest of the options in this file are ignored." should say "... all of this file is ignored" as clearly AUTOSTART is ignored if favour of this method. – Rodney May 11 at 9:37

Indeed @xm88, you want to automatically provide credentials at boot time when openvpn service is started up without user interaction or typing

In your oven config file (.conf on raspbian, but whichever extension is needed in your case)

    auth-user-pass $yourCredentialsFile
    [some more config]
    etc etc

And right next to your config file, a plain text file named $yourCredentialsFile which will contain:


I must advise this is not best practice in terms of security, because credentials are plain and available to any user who has access to your openvpn config dir /etc/openvpn, but this will allow openvpn service to auto login when started up at boot time.

  • I guess that the specific question is: how to have it auto start at boot time. – vanadium Sep 13 '18 at 17:11

Below you find the steps I did to configure my Private Internet Access OpenVPN tunnel. It might me useful. I used Ubuntu sever 18.04, but it should work on any Linux distro using systemd. I only don't know if the network-manager will override this or not.

  1. sudo apt update
  2. sudo apt install openvpn
Openvpn settings
  1. sudo touch /etc/openvpn/PIA
  2. sudo wget https://www.privateinternetaccess.com/openvpn/openvpn.zip https://www.privateinternetaccess.com/openvpn/openvpn-strong.zip
  3. Extract files and copy into folder (/etc/openvpn/PIA)
  4. cd /etc/openvpn/PIA
  5. sudo touch piapass.txt
  6. sudo chmod 700 piapass.txt
  7. sudo nano piapass.txt username password
  8. sudo nano Switzerland.ovpn change "auth-user-pass" to "auth-user-pass /etc/openvpn/PIA/piapass.txt"
  9. Test connection sudo openvpn Switzerland.ovpn
systemd startup
  1. cd /etc/systemd/systemd/
  2. sudo touch piavpn.services
  3. sudo chmod 644 piavpn.services
  4. sudo nano piavpn.services [Unit] Description=Private Internet Access VPN (Swiss) After=multi-user.target

    [Service] Type=idle ExecStart=/usr/sbin/openvpn --config /etc/openvpn/PIA/Switzerland.ovpn

    [Install] WantedBy=multi-user.target

  5. sudo systemctl daemon-reload
  6. sudo systemctl enable piavpn.service
  7. sudo reboot

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.