On Linux you don’t need to install OpenVPN because it’s already installed. However, configuration especially via the network manager can be tricky.
Install this additional package on your distro to display a new OpenVPN option in the network manager:
sudo apt-get install network-manager-openvpn-gnome
If you’re migrating from Windows and you’ve already a Windows installation of OpenVPN you can copy .key, .crt, .conf and .ovpn files from the OpenVPN location. Copy these files to your Linux home (e.g. ~/openvpn/) and reshape permissions to allow the access only to the owner.
After you’ve the .ovpn, .crt, .key files locally, you can test the connection using these commands:
cd ~/openvpn/; sudo openvpn my-openvpn-file.ovpn
Type the sudo password, wait and the connection should be established successfully. Press Ctrl+C to stop the VPN from command line.
Now you can configure the Network Manager to accept the .ovpn file.
Click on the network icon on the top right corner of the screen, click current connection, select settings and look for VPN Settings from the opened window.
Click the + icon aside the VPN title and select Import from file…
Select the my-openvpn-file.ovpn you’ve checked before. A form containing user certificate, CA, private key and the gateway will be automatically filled. Input the password in the last field when needed.
It’s very important to select .ovpn and not .conf since the latter will not work.
If the private key is password protected you can also type the password and on Advanced you can do some fine tuning but it’s usually unnecessary.
(Only for Ubuntu < 20) On the Details tab, uncheck the automatic connection option if you don’t want to start the VPN at every login.
You can also choose if you want to allow other users to access the connection after save.
On IPv4 and IPv6 you can disable a specific protocol or limit the connection to “Use this connection only for resources on its network“. This last step is particularly important because using VPN can limit network connection.
Press Apply and you should be able to connect pressing the network icon on the top right corner > VPN > your VPN name.
To list saved connections:
Programmatically connect / disconnect to VPN
If you need to write a script to use this imported connection, you can use openvpn command but you have to set all the parameters manually.
To reuse the saved connection instead, you can simply use nmcli to connect:
nmcli con up id my-connection-name
nmcli con down id my-connection-name
Tested on Ubuntu 20, 18 and 17.