I'm having this tricky problem trying to automatize a connection to a VPN. I have to ask for a password every time I want to connect, but I've already managed to request and parse it. The problem now is, when I execute nmcli to connect to the VPN, it gives me this error

Active connection state: unknown
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/11
state: VPN connecting (need authentication) (2)
state: VPN connecting (3)
state: VPN connecting (getting IP configuration) (4)
Error: Connection activation failed: unknown reason.

However, if I execute this as a command from a terminal, it works just fine. This is really driving me mad because I have no idea of what could it possibly be. Here is the source of the script:

# [...] fetch $password
sed -i 's/^password=.*$/password=$password/g' $VPNFILE
sudo grep password $VPNFILE  # $password is actually modified on the file
sudo nmcli con up id $VPN

$VPNFILE is the /etc/NetworkManager/system-connections associated file. Googling the error I found this thread with a similar problem, where the error was a wrong password, but that's not the problem here since grep gives the expected output.

Any ideas about the logic behind this issue and/or how to fix it?

Thank you for your time.

  • I've arrived to the conclusion that the problem is sed. For whatever reason, if I put a sleep instead of sed in the script and replace the password in $VPNFILE via sed in another terminal it just works. I think this is really weird, but still don't know why is it exactly failing to connect nor the fix to it (besides the obvious approach I've "discovered") – cronos2 Jan 22 '15 at 22:06
  • Is changing your connection file in /etc/NetworkManager/system-connections/ an option? You could hardcode the password into that: [vpn-secrets] (new line) password=xxxxxxx. Works fine for me. – nhee May 30 '15 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.