How to import a OpenVPN .ovpn file with Network Manager or Command Line in Linux

I have installed an OpenVPN server on a Debian Linux server. I have a client.ovpn file for my VPN server. How do I use it with Network Manager GUI? Is it possible to install or import client.ovpn file using the command line with Network Manager on a Ubuntu Linux or CentOS Linux desktop?

The Gnome NetworkManager has pluggable support for VPN software, including Cisco compatible VPNs (using vpnc), openvpn, and Point-to-Point Tunneling Protocol (PPTP). You need to simply install the NetworkManager VPN plugin and configure the users machines with the VPN’s settings.
How to use a .ovpn file with Network Manager in linux
This page explains how to import .opvn (OpenVPN config) file using a GUI or CLI method in Linux.


Step 1 – Install OpenVPN plugin

Type the following apt-get command or apt command to install the Gnome NetworkManager OpenVPN plugin:
$ sudo apt install network-manager-openvpn-gnome openvpn-systemd-resolved
Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libnm-glib-vpn1 libnss-resolve libpkcs11-helper1 network-manager-openvpn openvpn
Suggested packages:
  resolvconf easy-rsa
The following NEW packages will be installed:
  libnm-glib-vpn1 libnss-resolve libpkcs11-helper1 network-manager-openvpn network-manager-openvpn-gnome openvpn openvpn-systemd-resolved
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 747 kB of archives.
After this operation, 2,345 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 artful/main amd64 libnm-glib-vpn1 amd64 1.8.4-1ubuntu3 [13.8 kB]
Get:2 artful/universe amd64 libnss-resolve amd64 234-2ubuntu12 [110 kB]
Get:3 artful/main amd64 libpkcs11-helper1 amd64 1.22-2 [44.2 kB]
Get:4 artful/main amd64 openvpn amd64 2.4.3-4ubuntu1 [469 kB]
Get:5 artful/main amd64 network-manager-openvpn amd64 1.2.10-0ubuntu2 [30.6 kB]
Get:6 artful/universe amd64 network-manager-openvpn-gnome amd64 1.2.10-0ubuntu2 [71.0 kB]
Get:7 artful/universe amd64 openvpn-systemd-resolved amd64 1.2.6-1 [8,626 B]
Fetched 747 kB in 3s (206 kB/s)                      
Preconfiguring packages ...
Selecting previously unselected package libnm-glib-vpn1:amd64.
(Reading database ... 197667 files and directories currently installed.)
Preparing to unpack .../0-libnm-glib-vpn1_1.8.4-1ubuntu3_amd64.deb ...
Unpacking libnm-glib-vpn1:amd64 (1.8.4-1ubuntu3) ...
Selecting previously unselected package libnss-resolve:amd64.
Preparing to unpack .../1-libnss-resolve_234-2ubuntu12_amd64.deb ...
Unpacking libnss-resolve:amd64 (234-2ubuntu12) ...
Selecting previously unselected package libpkcs11-helper1:amd64.
Preparing to unpack .../2-libpkcs11-helper1_1.22-2_amd64.deb ...
Unpacking libpkcs11-helper1:amd64 (1.22-2) ...
Selecting previously unselected package openvpn.
Preparing to unpack .../3-openvpn_2.4.3-4ubuntu1_amd64.deb ...
Unpacking openvpn (2.4.3-4ubuntu1) ...
Selecting previously unselected package network-manager-openvpn.
Preparing to unpack .../4-network-manager-openvpn_1.2.10-0ubuntu2_amd64.deb ...
Unpacking network-manager-openvpn (1.2.10-0ubuntu2) ...
Selecting previously unselected package network-manager-openvpn-gnome.
Preparing to unpack .../5-network-manager-openvpn-gnome_1.2.10-0ubuntu2_amd64.deb ...
Unpacking network-manager-openvpn-gnome (1.2.10-0ubuntu2) ...
Selecting previously unselected package openvpn-systemd-resolved.
Preparing to unpack .../6-openvpn-systemd-resolved_1.2.6-1_amd64.deb ...
Unpacking openvpn-systemd-resolved (1.2.6-1) ...
Setting up libnm-glib-vpn1:amd64 (1.8.4-1ubuntu3) ...
Processing triggers for ureadahead (0.100.0-20) ...
Setting up libpkcs11-helper1:amd64 (1.22-2) ...
Setting up openvpn (2.4.3-4ubuntu1) ...
Processing triggers for libc-bin (2.26-0ubuntu2) ...
Processing triggers for systemd (234-2ubuntu12) ...
Setting up libnss-resolve:amd64 (234-2ubuntu12) ...
First installation detected...
Checking NSS setup...
Processing triggers for man-db ( ...
Processing triggers for dbus (1.10.22-1ubuntu1) ...
Setting up openvpn-systemd-resolved (1.2.6-1) ...
Setting up network-manager-openvpn (1.2.10-0ubuntu2) ...
Setting up network-manager-openvpn-gnome (1.2.10-0ubuntu2) ...
Processing triggers for libc-bin (2.26-0ubuntu2) ...

Step 2 – How to import OpenVPN config file from command line with NetworkManager (method #1)

Open the Terminal application. The syntax is:
sudo nmcli connection import type openvpn file /path/to/your.ovpn
For example:
$ sudo nmcli connection import type openvpn file /home/vivek/ubuntu16.04LTS.ovpn
Sample outputs:

Connection 'ubuntu16.04LTS' (989b8c5a-0851-48ae-813c-c74eb593014d) successfully added.

Your connection is called ‘ubuntu16.04LTS’ and to make connection to the OpenVPN server, run:
$ nmcli connection up ubuntu16.04LTS
Sample outputs:

 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/27)

To see OpenVPN connection details:
$ nmcli connection show ubuntu16.04LTS
To see IPv4/IPv6 OpenVPN client IP and other info, run:
$ nmcli connection show ubuntu16.04LTS | egrep -i 'IP4|IPV6'
$ nmcli connection show ubuntu16.04LTS | egrep -i 'IP4'

Sample outputs:


Verify it with the ping command i.e. send ping-pong requests to OpenVPN gateway:
$ ping -c 4
Sample outputs:

PING vpn ( 56(84) bytes of data.
64 bytes from vpn ( icmp_seq=1 ttl=64 time=288 ms
64 bytes from vpn ( icmp_seq=2 ttl=64 time=279 ms
64 bytes from vpn ( icmp_seq=3 ttl=64 time=172 ms
64 bytes from vpn ( icmp_seq=4 ttl=64 time=77.5 ms
--- vpn ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 77.547/204.609/288.526/86.425 ms

Step 3 – Import a .ovpn file with Network Manager GUI (method #2)

Open Network Manager from Gnome settings option and select Network tab and click on the VPN + symbol:

Fig.01: Configuring OpenVPN client

Fig.01: Configuring OpenVPN client

From the Add VPN windows, click on the “Import from file…” option:
Fig.02: Click on "Import from file..."

Fig.02: Click on “Import from file…”

You must navigate to your .ovpn file (/home/vivek/ubuntu16.04LTS.ovpn) and click on Open button:
Fig.3: Navigate your file system and select the file to import

Fig.3: Navigate your file system and select the file to import

Click on the Add button:
Fig.04: You can see all settings imported. Make sure IPv4/IPv6 and routing/DNS all set to automatic.

Fig.04: You can see all settings imported. Make sure IPv4/IPv6 and routing/DNS all set to automatic.

Finally, click on off button to turn on the VPN:
Fig.05: Testing your OpenVPN client

Fig.05: Testing your OpenVPN client

You can now browse the Internet using your VPN server. Test it using ping command/dig command/host command:
$ ping
$ host

To find out your IP address i.e. make sure you public IP address changed after connecting to the OpenVPN server, run:
$ dig +short
$ dig TXT +short
And, there you have it a .ovpn file with Network Manager GUI/CLI imported directly for connection purpose on Linux operating system.
🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

3 comments… add one
  • Alejandro Nov 30, 2017 @ 8:48

    Is there a way for making work if the vpn has an aditional challenge like Google Authenticator?

  • Kai Aug 19, 2020 @ 6:25

    If somebody else runs into the issue on Fedora 32 (Kernel 5.7.15-200.fc32.x86_64) that the openvpn plugin fails (VPN plugin: failed: connect-failed (1)): The certificates were included in my .ovpn file. When importing this file, the certificates will be extracted and saved under /root/.cert

    The solution from this ticket in the Red Hat Bugtracker solved the issue for me:
    Please run as root or with sudo to fix labels of cert files. :
    restorecon -Rv /root/.cert/

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.