Apr 17, 2026 by Arnaud Stoz | 47 views
https://cylab.be/blog/501/managing-openvpn-connection-via-nmcli-a-comprehensive-guide
Managing OpenVPN via nmcli provides a streamlined, scriptable alternative to manual configuration, particularly in CLI-only environments. This guide covers importing configurations, securing credentials, and managing routing using NetworkManager.
To import an existing .ovpn profile into NetworkManager, use the following command:
nmcli connection import type openvpn file /path/to/your/config.ovpn
Note: Ensure the network-manager-openvpn plugin is installed on your system.
If the VPN requires authentication, inject the username and password directly into the connection profile:
# Set the username
nmcli connection modify "<connection_name>" vpn.data "username=your_username"
# Set the password
nmcli connection modify "<connection_name>" vpn.secrets "password=your_password"
Enter your command following a space to ensure it is not recorded in the history.
you can also choose to type credentials and password every time you want to connect.
By default, an OpenVPN connection may set itself as the system’s default gateway, which can prevent access to the regular internet. To prevent this and only route specific traffic through the tunnel, set ipv4.never-default to yes:
# Disable the default route
nmcli connection modify "<connection_name>" ipv4.never-default yes
# Restart the connection to apply changes
nmcli connection down "<connection_name>"
nmcli connection up "<connection_name>"
Using nmcli to manage OpenVPN connections provides a powerful and flexible way to handle VPN configurations in a CLI environment. Happy networking!
This blog post is licensed under
CC BY-SA 4.0
Linux Sysadmin
Sysadmin VPN
Sysadmin
SSH was created in 1995 by Tatu Ylönen, a researcher at the Helsinki University of Technology in Finland [1]. Over more than 30 years of existence, it has evolved to offer more security. But once in a while you may have to SSH into an older device that does not support modern SSH algorithms and mechanisms. This is typically the case to configure network devices like switches.