Starting OpenVPN client automatically at boot

Edit /etc/default/openvpn. Just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

sudo gedit /etc/default/openvpn

Uncomment the AUTOSTART="all" line. Save and close. Reboot your system.

image


If you're on systemd (16.04) , configured AUTOSTART="all" and it's still not starting pay attention to this:

> # If you're running systemd, changing this variable will
> # require running "systemctl daemon-reload" followed by
> # a restart of the openvpn service (if you removed entries
> # you may have to stop those manually)

Just do a

systemctl daemon-reload

and then restart the service

 sudo service openvpn restart

You can put auth-user-pass filename in your anonine.ovpn where filename is the file with username/password on 2 lines.

Make sure that filename is properly secured, because it will contain plain username/password.

This is from openvpn --help:

Client options (when connecting to a multi-client server):

--auth-user-pass [up] : Authenticate with server using username/password.
                  up is a file containing username/password on 2 lines,
                  or omit to prompt from console.

You also can add your certificate to your anonine.ovpn adding it this way:

<ca>
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
</ca>

If a username / password is not required in order to connect, then rename the .ovpn files to have an extension of .conf.

OpenVPN should connect on boot, even without autostart=all.

If a username/password is required,

edit the .conf file

edit auth-user-pass user-password-filename

Create a file containing:

username
password

If you want to connect with Network Manager, make sure you first do:

sudo apt-get install network-manager-openvpn

Make sure your Ubuntu is at least 14.04. This doesn't work on 12.04.

If you don't have your ca.crt, client.crt, etc, extract them from .conf.

With Network Manager, create a new VPN connection or import your conf.

Add the certificates and ta.key.

Routes, use connection only for resources on its network.

Edit your Internet connection with network manager. Choose connect with VPN, then choose your VPN connection.