Error when trying to connect to VPN on startup
The problem seems to be, that your password in keyring is not accessible.
Source
Solution mentioned there is to open file /etc/NetworkManager/system-connections/ConnectionName and set the
password-flags=0
and add the below lines to the file
[vpn-secrets]
password=YourPassword
Then restart network manager to pick up the change:
sudo restart network-manager
For more info refer the source
To start VPN automatically at startup
Assuming you have your credentials files working, you should be able to use a dispatcher.d
script like you originally had to start your VPN. I've modified your script a bit to get it working with 2 connections (Wireless router at home, and wired connection at work). The reason for this is that I want it to start the VPN if it's not started when either of my required internet connections are alive. In my example, I've configured them with default names, but you should change them to match your own names.
Put this in the file /etc/NetworkManager/dispatcher.d/vpn-up
, and make executable with chmod +x
#! /bin/bash
REQUIRED_CONNECTION1_NAME="linksys"
REQUIRED_CONNECTION2_NAME="Wired connection 1"
VPN_CONNECTION_NAME="My VPN"
activ_con=$(nmcli con status | grep "${REQUIRED_CONNECTION1_NAME}\|${REQUIRED_CONNECTION2_NAME}")
activ_vpn=$(nmcli con status | grep "${VPN_CONNECTION_NAME}")
if [ "${activ_con}" -a ! "${activ_vpn}" ];
then
nmcli con up id "${VPN_CONNECTION_NAME}"
fi
To configure client certificates in NetworkManager
If you are using a client cert with password to authenticate to your VPN, it is a bit undocumented.
After browsing through the NetworkManager 0.9 settings specification, I was unable to determine how to specify a vpn cert pass in the config file. I opened up seahorse
and found my 'VPN secret' (certificate password).
It was listed as something like 'VPN cert-pass secret for My VPN/org.freedesktop.NetworkManager.openvpn/vpn'. Clicking on the details tab gave me a clue for the setting-key
name:
setting-name: vpn
setting-key: cert-pass
connection-uuid: 0badcafe-f00d-dead-beef-feedfacef00d
To start a VPN automatically as root on Ubuntu 12.04 (Precise Pangolin) using NetworkManager 0.9.4.0:
Open /etc/NetworkManager/system-connections/My VPN
and add the cert-pass
VPN secret so the file looks like:
[connection]
id=My VPN
uuid=0badcafe-f00d-dead-beef-feedfacef00d
type=vpn
timestamp=1234567890
[vpn]
service-type=org.freedesktop.NetworkManager.openvpn
key=/home/<your-user>/path/to/certs/your.secure.key
ca=/home/<your-user>/path/to/certs/your.vpnca.crt
connection-type=tls
cert=/home/<your-user>/path/to/certs/your.crt
remote=your.vpn-server.com
cert-pass-flags=0
[vpn-secrets]
cert-pass=your-vpn-pass
[ipv4]
method=auto
never-default=true