Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have two VPNs setup on my Ubuntu machine, one using vpnc and one using PPTP. These were both setup using the GNOME network manager interfaces and work great. However on occasion I need to access this machine remotely - is there a way to connect or disconnect to these VPNs from the command line?

share|improve this question
    
Does the vpnc command detailed here not work for you? Also, there are instructions for configuring and connecting to PPTP here. Do they not work? –  Kris Harper Aug 16 '11 at 18:23

1 Answer 1

up vote 65 down vote accepted

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

list all NM connections: nmcli con

start connection (wifi, vpn, etc): nmcli con up id ConnectionName

down connection: nmcli con down id ConnectionName

(more nmcli commands in the nmcli manpage).


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 "Error: Connection activation failed: no valid VPN secrets."

If that happens to you, it's likely that the VPN password is stored in your user's gnome-keyring, which makes it inaccessible to the root user. This comment explains why.

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.

share|improve this answer
    
I wish there was a general disconnect command that would disconnect any VPN without having to specify its id. That would probably make this feature (I want) easier to implement. –  Lonnie Best Jul 6 at 23:15
    
If you're using ipsec (e.g. vpnc), you may also need to add "IPSec secret-flags=0" and "IPSec secret=<grouppw>" in their respective places –  Matt Nov 3 at 0:01
    
Thank you, that was useful. –  Sushiant Nov 13 at 0:10

protected by Community May 31 '12 at 18:58

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.