Provide password to `nmcli con up` in terminal 14.04
Solution 1
You can write-update a password to a seperate file. This works for me:
echo "vpn.secrets.password:MY_PASSWORD" > /my/vpn/password
nmcli con up uuid MY_UUID passwd-file /my/vpn/password
Solution 2
In case you need to create the password with a script or similar and then pass it to nmcli without storing it on the disk, the following works for me (nmcli 1.30.0) and might be possible to be adapted:
echo vpn.secrets.password:$PW | /usr/bin/nmcli c up $VPN_CON_NAME passwd-file /dev/fd/0
It unfortunately does not support the standard linux -
for standard input...
Solution 3
You can set the password using the following command:
nmcli con mod VPNID vpn.secrets "password=VPNPASS"
where VPNPASS is the VPN password.
In order for this to work, you have to enable the pasword storage option in NetworkManager, as shown in this picture:
I am using Ubuntu 16.04.
Solution 4
There is a more elegant and secure way to work around this. Store your password in gnome-keyring:
~$ sudo apt install libsecret-tools
~$ secret-tool store --label='vpn' vpn_name your_unique_vpn_name
Now let’s have a script to bring up the vpn. The key to be provided by the way may differ. In my example it is vpn.secrets.cert-pass
. The script should be put into ~/bin/
.
#!/bin/sh -e
vpn=your_vpn_connections_name
tmp=$(mktemp)
chmod 600 $tmp
printf "vpn.secrets.cert-pass:$(secret-tool lookup vpn_name your_unique_vpn_name)">$tmp
nmcli c u "$vpn" passwd-file $tmp
rm $tmp
Related videos on Youtube
Comments
-
barunsthakur over 1 year
I am trying to connect to my VPN using terminal. My VPN password is a TOTP, so cannot save it to the connection conf file. When I try to connect, a dialog appear to enter password. I want to do it in terminal itself as I can generate my TOTP from a script. I just couldn't figure out any way. Is there a way to specify password in command line or send password from command line to the dialog?
-
barunsthakur almost 8 yearsI forgot to mention the ubuntu version. I am using 14.04 and according to docs
passwd-file
is not supported. Any alternative? -
palash kulshreshtha almost 7 years@barunsthakur did it work for you in 14.04 despite no parameter passwd-file?
-
sam about 6 years
Unknown parameter : passwd-file
inubuntu 14.04 LTS
-
avi over 4 yearsThe picture was really all I needed.