Ubuntu – How to enter password on console with NetworkManager’s nmcli


I want to connect to a VPN with nmcli. Is there a way to allow me to provide a password to nmcli from the console?

There seem to be ways to store the password in /etc/NetworkManager/system-connections/<connection>, that I don't seem to be able to get working. But I'd prefer not storing passwords in files at all.

On the desktop I enter the password every time, but when I run sudo nmcli con up id MyVPN over SSH, it opens a GUI dialog on the remote desktop asking for my password, which seems like a strange design decision to me. If I had e.g. VNC to the remote desktop, I wouldn't use nmcli

Best Answer

Try using the --ask flag:

nmcli --ask con up id MyVPN

I've dropped sudo because it is probably unnecessary (and dangerous).