13

I have a working VPN connection using NetworkManager, OpenConnect, and the network-manager-openconnect-gnome package, but I have to start it manually every time I connect to a network, and I have to enter my password manually each time.

How can I get it to connect automatically, and remember my password (securely)?

I have checked the 'Connect Automatically' box on the Configure VPN page, but this seems to have no effect. I've also got the 'Start connecting automatically' box checked in the pop-up box, and that does avoid the need to press the connect button in that window, but seems to have no part in kicking off the whole process in the first place. There is no option to remember the password in the window, but maybe there's one somewhere else?

4 Answers 4

7

When setting up a VPN connection through Network Manager selecting the Connect automatically option should mean that the VPN does automatically connect, however this isn't working due to a bug: https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/280571

It can still achieved though through workarounds, one way of doing this would be to use vpnautoconnect

  • Set up your VPN as normal through the network settings, making sure that Connect automatically is selected:

enter image description here

enter image description here

  • Select Preferences from the VPNautoconnect menu

enter image description here

  • Click the small arrow to create a new tab and select your wireless connection in the Parent Connection drop down menu, and your VPN in the VPN Connection drop down menu. Then click Save

enter image description here

enter image description here

Your VPN should now connect automatically whenever the selected wireless network is connected (if you use more than one wireless network you'll need to create a new tab in the preferences menu for each one you want to auto connect to a VPN whilst you are using).

2
  • 1
    I really like that swirly blur effect. +1 for that and a good answer!
    – jrg
    Jun 8, 2012 at 10:59
  • 1
    I followed your directions, and it worked. Now my VPN connection automatically attempts to reconnect. However, my password is not saved. How do you save the VPN password? I have found no relevant documentation with a clear answer after extensive Google searching for many hours. May 19, 2014 at 17:44
2

In Ubuntu Gnome 16.04, I can't find in Network Connections the GUI option to edit per-network VPN settings. The solution for me was to launch the "Network Connections" panel manually in the terminal by typing:

nm-connection-editor

then edit the desired network and add a VPN connection to it.

1
  • This worked for me on Arch Linux using Gnome, thanks for sharing this. Jul 4, 2018 at 13:35
2

On 18.04, and some previous version also, there is not even a GUI settings to automatically enable a VPN connection now.

So instead, I enable automatic connection to ethernet and then setup the VPN connection with an autostart config file and script.

Add a vpn.desktop file in ~/.config/autostart with the following content

[Desktop Entry]
Name=Start VPN connection
GenericName=Network helper
Comment=Start automatically VPN connection
Exec=/home/me/bin/vpn-start.sh
Terminal=false
Type=Application
Icon=network-vpn
Categories=Network;
StartupNotify=false
X-GNOME-Autostart-enabled=true

This will call a file that you can put everywhere, but I have put in in /home/me/bin/ and call it vpn-start.sh

#/bin/bash
LANG=C
while ! nmcli dev status|grep -q connected; do
    sleep 1
done
exec nmcli con up '<name of your vpn connection>'

You need to put the name of your VPN connection. Look for it in the output of nmcli con show.

Make it executable with chmox +x vpn-start.sh.

And logout-relogin to test for it.

2
  • 1
    Via askubuntu.com/questions/1033278/… I found that I could use nm-connection-editor in Ubuntu 18.04 to set "Automatically connect to VPN when using this connection" under the "General" tab for the connection(s) in question. No more manually running vpn-start.sh! Jun 21, 2018 at 3:23
  • Confirmed this works on my 16.04 and nmcli 1.2.6.
    – IsaacS
    Mar 27, 2020 at 0:05
2

Seems like autoconnect doesn't work with VPN profiles but you can use secondaries instead. See here https://manpages.debian.org/testing/network-manager/nm-settings.5.en.html. What I did:

List all existing connections:

sudo \ls -l /etc/NetworkManager/system-connections/

Open a file of the corresponding VPN connection (my-VPN in my case):

sudo gedit /etc/NetworkManager/system-connections/my-VPN

Then copy uuid. It should look like this 5a9bde6f-54ge-4h41-8754-f1a2977fa564.

Open your Wi-fi connection file:

sudo gedit /etc/NetworkManager/system-connections/My-Wi-Fi

And add secondaries property with copied uuid. It should look like this:

[connection]
id=My-Wi-Fi
uuid=1ab56231-9401-48c7-82de-a9ffghtyeac4
type=wifi
interface-name=wlo1
permissions=
secondaries=5a9bde6f-54ge-4h41-8754-f1a2977fa564;
timestamp=1649182910

[wifi]
...

After that restart NetworkManager or your computer:

systemctl restart NetworkManager

Now every time you connect to My-Wi-Fi my-VPN connects too

1
  • This is the perfect solution for automatically connecting to a VPN on certain public networks, and automatically disconnecting when connected to other networks. This is just what I was looking for and it's working perfectly. Oct 4, 2023 at 19:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .