LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux Mint
User Name
Password
Linux Mint This forum is for the discussion of Linux Mint.

Notices


Reply
  Search this Thread
Old 03-24-2017, 04:02 PM   #1
Thane
Member
 
Registered: Aug 2006
Location: Ontario,Canada
Distribution: Linux Mint19.3 Cinnamon 64bit
Posts: 223

Rep: Reputation: Disabled
How to make a vpn connection persistent on reboot


I have a workable vpn connection (NordVPN), which at present needs to be manually connected after each reboot. I would like to have the vpn automatically connected on startup. Is there a way to do this? Linux Mint 18 64bit, eth0 dhcp connection. Thanks
 
Old 03-24-2017, 10:11 PM   #2
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,802

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Are you using NetworkManager to manage your network settings? If so, a NetworkManager dispatcher script will do the job of starting the VPN as soon as the network is up. For example
http://askubuntu.com/questions/43465...etwork-manager
 
Old 03-25-2017, 02:55 PM   #3
Thane
Member
 
Registered: Aug 2006
Location: Ontario,Canada
Distribution: Linux Mint19.3 Cinnamon 64bit
Posts: 223

Original Poster
Rep: Reputation: Disabled
Thanks for the reply. I've made some progress, but have stalled out now. I checked my connection names with
Code:
nmcli con show
as suggested and then used vim to make a
Code:
/etc/NetworkManager/dispatcher.d/vpn-up
script file from ferrari's link plugging in my eth0 and vpn connection names.

Code:
REQUIRED_CONNECTION_NAME="Ethernet connection dhcp"
VPN_CONNECTION_NAME="uk19.nordvpn.com.tcp443"


default_conn=$(nmcli con show --active | grep "${REQUIRED_CONNECTION_NAME}")
vpn_conn=$(nmcli con show id | grep "${VPN_CONNECTION_NAME}")
if [ "${default_conn}" -a ! "${vpn_conn}" ];
then
    nmcli con up id "${VPN_CONNECTION_NAME}"
fi
After a restart /var/log/syslog showed a permissions error on this file, so I modified the permissions with
Code:
sudo chmod 755 /etc/NetworkManager/dispatcher.d/vpn-up
and the permissions seem to be fine now. But on startup now the vpn still won't connect automatically and the syslog file error message states:

Code:
Mar 25 15:15:02 x nm-dispatcher[1678]: Warning: password for 'vpn.secrets.password' not given in 'passwd-file' and nmcli cannot ask without '--ask' option.
Mar 25 15:15:02 x NetworkManager[1276]: <error> [1490469302.7591] vpn-connection[XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,"XXXX.nordvpn.com.tcp443",0]: Failed to request VPN secrets #3: No agents were available for this request.
Mar 25 15:15:02 x nm-dispatcher[1678]: Error: Connection activation failed: no valid VPN secrets.
Mar 25 15:15:02 x nm-dispatcher: req:2 'up' [enp1s0], "/etc/NetworkManager/dispatcher.d/vpn-up": complete: failed with Script '/etc/NetworkManager/dispatcher.d/vpn-up' exited with error status 4.
Mar 25 15:15:02 x NetworkManager[1276]: <warn>  [1490469302.7652] dispatcher: (3) vpn-up failed (failed): Script '/etc/NetworkManager/dispatcher.d/vpn-up' exited with error status 4.
I have tried plugging in my NordVPN password into the "Authentications" box of the Mint Network Connections entry for my vpn. But that doesn't solve the problem. Also I cannot find a "vpn.secrets.password" or "passwd-file" anywhere on my system as referenced in the /var/log/syslog errors.
 
Old 03-25-2017, 03:07 PM   #4
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,802

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
You may need to (re)define the connections as system-wide connections first, so that the credentials are stored in the connection config files themselves, as opposed to a password manager (for user-specific connection profiles).
 
Old 03-25-2017, 10:00 PM   #5
Thane
Member
 
Registered: Aug 2006
Location: Ontario,Canada
Distribution: Linux Mint19.3 Cinnamon 64bit
Posts: 223

Original Poster
Rep: Reputation: Disabled
Afraid I'm having no success now. I have the system to the point, that on reboot the eth0 will not connect automatically. But if I click on eth0 in the NetworkManager menu, both eth0 and the vpn both connect. Checking my /var/log/syslog file, I now have the following entries:

Code:
Mar 25 22:41:45 x NetworkManager[1234]: <info>  [1490496105.5056] vpn-connection[XXXXXXXXXXXX,"uk19.nordvpn.com.tcp443",0]: VPN connection: (ConnectInteractive) reply received
Mar 25 22:41:45 x nm-openvpn[1820]: Options error: --ca fails with '/home/x/.cert/nm-openvpn/uk19.nordvpn.com.tcp443-ca.pem': No such file or directory
Mar 25 22:41:45 x nm-openvpn[1820]: Options error: --tls-auth fails with '/home/x/.cert/nm-openvpn/uk19.nordvpn.com.tcp443-tls-auth.pem': No such file or directory
Mar 25 22:41:45 x nm-openvpn[1820]: Options error: Please correct these errors.
Mar 25 22:41:45 x NetworkManager[1234]: (nm-openvpn-service:1817): nm-openvpn-WARNING **: openvpn[1820] exited with error code 1
Mar 25 22:41:45 x nm-openvpn[1820]: Use --help for more information.
Mar 25 22:41:45 x NetworkManager[1234]: <warn>  [1490496105.5090] vpn-connection[XXXXXXX,"uk19.nordvpn.com.tcp443",0]: VPN plugin: failed: connect-failed (1)
Mar 25 22:41:45 x NetworkManager[1234]: <warn>  [1490496105.5090] vpn-connection[XXXXXXXXXXXXXXXXXXX,"uk19.nordvpn.com.tcp443",0]: VPN plugin: failed: connect-failed (1)
Mar 25 22:41:45 x NetworkManager[1234]: <info>  [1490496105.5091] vpn-connection[XXXXXXXXXXXX,"uk19.nordvpn.com.tcp443",0]: VPN plugin: state changed: stopping (5)
Mar 25 22:41:45 x NetworkManager[1234]: <info>  [1490496105.5092] vpn-connection[XXXXXXXXXXXXXXXXXXX,"uk19.nordvpn.com.tcp443",0]: VPN plugin: state changed: stopped (6)
Mar 25 22:41:45 x NetworkManager[1234]: <info>  [1490496105.5104] vpn-connection[XXXXXXXXXX,"uk19.nordvpn.com.tcp443",0]: VPN plugin: state change reason: unknown (0)
Mar 25 22:41:45 x NetworkManager[1234]: <info>  [1490496105.5104] device (enp1s0): state change: secondaries -> failed (reason 'secondary-connection-failed') [90 120 54]
Mar 25 22:41:45 x NetworkManager[1234]: <info>  [1490496105.5106] manager: NetworkManager state is now DISCONNECTED
I have checked and I do have the files listed as problems:
Code:
/home/x/.cert/nm-openvpn/uk19.nordvpn.com.tcp443-ca.pem
and
Code:
/home/x/.cert/nm-openvpn/uk19.nordvpn.com.tcp443-tls-auth.pem
.

Totally confused now.
 
Old 03-25-2017, 11:26 PM   #6
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,802

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
It's not clear to me why that would fail either, but hopefully someone else may know.

As an alternative to using the dispatcher script, perhaps you could just acivate the VPN when the desktop starts via an autostart script instead.

http://askubuntu.com/questions/20968...nnamon-desktop
 
Old 03-25-2017, 11:33 PM   #7
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,802

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
BTW, you're not using an encrypted home folder by chance are you?
 
Old 03-26-2017, 12:22 AM   #8
Thane
Member
 
Registered: Aug 2006
Location: Ontario,Canada
Distribution: Linux Mint19.3 Cinnamon 64bit
Posts: 223

Original Poster
Rep: Reputation: Disabled
Yes ferrari, I am using an encrypted /home folder.
 
Old 03-26-2017, 12:29 AM   #9
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,802

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Quote:
Yes ferrari, I am using an encrypted /home folder.
Well, there's the problem right there. You should relocate the relevant files to a directory outside of the encrypted home folder. The VPN connection will need to be edited to reflect the new location of the .pem files as well.
 
Old 03-26-2017, 04:24 PM   #10
Thane
Member
 
Registered: Aug 2006
Location: Ontario,Canada
Distribution: Linux Mint19.3 Cinnamon 64bit
Posts: 223

Original Poster
Rep: Reputation: Disabled
Thanks ferrari. It was no problem to copy the
Code:
nm-openvpn
folder with it's enclosed .pem files from my
Code:
/home/.cert/
folder to an
Code:
/etc/openvpn2/
folder. But the eth0 with the vpn still will not autostart on reboot. After searching through the syslog file and my filesystem for hours, I cannot find a file, that on initial startup will direct (openvpn?) to go to my new location to read the .pem files. I am assuming my eth0 will not start up automatically, because it now linked via NetworkManager with the vpn and as you have stated, my .pem files need to be accessed outside of the encrypted /home.
 
Old 03-26-2017, 05:53 PM   #11
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,802

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
I'm not sure if I completely understand you. The VPN connection profile is stored in the /etc/NetworkManager/system-connections/ directory eg /etc/NetworkManager/system-connections//uk19.nordvpn.com.tcp443

It should contain the path to the .pem files. You can either edit the connection via NM or edit the file directly (as root).
 
Old 03-26-2017, 09:38 PM   #12
Thane
Member
 
Registered: Aug 2006
Location: Ontario,Canada
Distribution: Linux Mint19.3 Cinnamon 64bit
Posts: 223

Original Poster
Rep: Reputation: Disabled
Thank you. I found the file. In
Code:
/etc/NetworkManager/system-connections/
have a uk19.nordvpn.com.tcp443 and also a uk19.nordvpn.com.tcp443_ file, the latter having permissions that needed sudo cat to read. The latter file is the one, with the path to the two .pem files. I had been ignoring this file before. Will modify those entries with vim and reboot to see what happens. The first of the two uk19 files is empty and I had assumed the other was as well. I will do the mods and report back. Many thanks ferrari.
 
Old 03-26-2017, 10:22 PM   #13
Thane
Member
 
Registered: Aug 2006
Location: Ontario,Canada
Distribution: Linux Mint19.3 Cinnamon 64bit
Posts: 223

Original Poster
Rep: Reputation: Disabled
Outstanding! Thank you so much ferrari for the guidance. The
Code:
/etc/NetworkManager/system-connections/uk19.nordvpn.com.tcp443_
file was the one that needed the mods. I have copied the .pem files from
Code:
/home/x/.cert/nm-openvpn/
into a new
Code:
/etc/openvpn2/nm-openvpn/
folder. Rebooted a couple of times and everything works. I will write myself a howto for future reference. cheers
 
Old 03-26-2017, 11:04 PM   #14
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,802

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Glad to have been of help
 
Old 06-21-2017, 09:24 PM   #15
Thane
Member
 
Registered: Aug 2006
Location: Ontario,Canada
Distribution: Linux Mint19.3 Cinnamon 64bit
Posts: 223

Original Poster
Rep: Reputation: Disabled
Just a follow-up as an fyi... Almost 3 months later and not a single glitch ever. Perfect!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to make modprobe persistent after reboot dmz1213 Linux - Newbie 3 02-13-2018 09:55 AM
script to change vpn connection if slow vpn connection andrew44 Linux - General 2 02-23-2014 11:25 AM
how to make vpn connection with opensuse 13.1 korth1 Linux - Networking 3 01-31-2014 02:16 PM
How to make network connection persistent again DJOtaku Linux - Networking 2 01-21-2012 10:03 AM
how to make a VPN connection with pap authentication LInxia Linux - Networking 2 09-06-2008 04:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux Mint

All times are GMT -5. The time now is 10:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration