When I wake the laptop from the sleep I need to get the VPN state as I left it (turned on). Can't find the setting of autoconnect in VPN settings... Need some easy way to ask the system to autoconnect the VPN when the internet is available.
Edit based on comments:
Ubuntu 18.04 has no option to Always connect to VPN when using using this connection.
If you go into your WiFi connection settings for the AP you want to connect to the VPN on, there is an Always connect to VPN when using this connection: option, which you can enable, and select the VPN which you wish to automatically connect to.
Then when you connect to this connection (or when it reconnects on wake from suspend), the system will also attempt to connect to the VPN upon successfully reconnecting to the designated WiFi AP.
It seems the changes in newer GNOME have removed this option from the main UI, so you need to run
nm-connection-editor
to edit the connection, which should make the option available again.It's not shown in the GUI, but you can still type
nm-connection-editor
in a terminal and select 'always connect to vpn...' under settings > general tab.
The "automatically connect to this VPN" checkbox has moved. Ubuntu 18.04. Run 'nm-connection-editor' and select the wifi network that you usually connect to. Click the gear, go to General tab. It's right there at the bottom - click the checkbox, then click the dropdown below and select the VPN you want to automatically connect to.
An addition to @dobey answer.
I found that the icon on the password setting on the VPN connfig window is actually clickable. It allows other system users to use vpn password, which is required to automatically connect to vpn after suspend.
When OpenVPN is already installed on your computer and have the configurations for OpenVPN, then follow this steps:
unzip openvpn.zip
sudo cp ~/Downloads/OpenVPN/'Northeast US.ovpn' /etc/openvpn/openvpn.conf
sudo
, then search for the lineauth-user-pass
and addauth.txt.
----> How does it looks like:auth-user-pass auth.txt
! Crate the file in the following directory"/etc/openvpn”
and type in there your username and password. More about that here.sudo systemctl enable openvpn
for those who are looking for a command-line solution, here you go:
first of all, you can list the existing VPN connections you created under this path:
after finding which VPN connection you want auto-connect, edit the corresponding file (
my-VPN
in my case)... and change the
autoconnect=true
, save and exit;note: Omit
sudo
from the command if you are under root user.use the
[sudo] nmcli connection edit
for interactive command-line connection editor.None of the solutions above worked for me.
I did some investigation on @αғsнιη solution with
autoconnect
and found out that you can usesecondaries
instead. See here https://manpages.debian.org/testing/network-manager/nm-settings.5.en.html. Also this page says that you can't useautoconnect
with VPN profiles. What I did:List all existing connections:
Open a file of the corresponding VPN connection (
my-VPN
in my case):Then copy
uuid
. It should look like this5a9bde6f-54ge-4h41-8754-f1a2977fa564
.Open your Wi-fi connection file:
And add
secondaries
property with copieduuid
. It should look like this:After that restart NetworkManager or your computer: