Sunday, April 28, 2024
302
rated 0 times [  302] [ 0]  / answers: 1 / hits: 272521  / 2 Years ago, wed, april 6, 2022, 5:17:27

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 interface 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?


More From » command-line

 Answers
5

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


If there is a line starting with Xauth password-flags, change it instead.



Then add the following below the [vpn] block:



[vpn-secrets]
password=YourPassword


(If in the previous step you changed the line Xauth password-flags, add Xauth password=... instead.)



Now restart network manager by:



sudo service network-manager restart


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


[#43837] Wednesday, April 6, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
iething

Total Points: 49
Total Questions: 127
Total Answers: 112

Location: Luxembourg
Member since Tue, Jan 25, 2022
2 Years ago
;