Ubuntu Tip:How to Connect/disconnect VPN from the command line

This tutorial will explain How to Connect/disconnect VPN from the command line

If you want to interact with NetworkManager from the command line you can use the "nmcli" command.

You can list all NM connections using the following command

nmcli con

You can start connection (wifi, vpn, etc) using the following command

nmcli con up id ConnectionName

You can disconnect the connection using the following command

nmcli con down id ConnectionName

Also note that regular users usually don't have permission to control networking. Using the commands above with sudo should work for most connections, but VPN specifically might fail with the following error

"Error: Connection activation failed: no valid VPN secrets."

Reason for this error

For most connection types, the default handling is that NM stores passwords itself. However, for certain connections,e.g. VPN, the passwords are rather
regarded as personal and thus they are stored by default in clients (e.g.keyring).

So, if you have configured my-openvpn connection for a user, but activate that under root, the password in user's keyring is not accessible.

To fix this, edit /etc/NetworkManager/system-connections/ConnectionName and under [vpn], change the password flags line to:


And add the following:


Then starting the VPN connection with sudo nmcli con up id ConnectionName should work without problems.

Thanks to Mark for this tip

Sponsored Link

You may also like...

4 Responses

  1. mescolar says:

    This solves our problem!!!

    Thx guy.

  2. Anonymous says:

    Solves my problem. Thanks!

  3. fred says:

    /etc/NetworkManager/system-connections/ConnectionName doesnt exist in ubuntu 14.04, anyone have any ideas?

  4. Jason Banks says:

    Fred, replace “ConnectionName” with the actual name of the VPN connection you want to edit.

Leave a Reply

Your email address will not be published. Required fields are marked *