Posted in Komputer, Tips-tips sederhana

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:

password-flags=0

And add the following:

[vpn-secrets]
password=YourPassword

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

Thanks to Mark for this tip

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s