Automatically start vpn on boot up ?

If none of the more specific forums is the right place to ask

Re: Automatically start vpn on boot up ?

Postby Chrisdb » 2020-02-29 13:25

parkerc wrote:Also I had tried to place the up-vpn.sh file into /etc/NetworkManager/dispatcher.d/ but it said I couldn’t as I didn’t have permission or something?


The script should indeed be located at:
Code: Select all
etc/NetworkManager/dispatcher.d


Did you try with sudo?
What's the exact command and error you got?
Chrisdb
 
Posts: 273
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

Postby parkerc » 2020-02-29 14:29

I was using the UI and right click ‘copy to’ command option to move it over into that folder, but it wouldn’t let me

The message is along the lines that I do not have the permissions necessary to save the file there .

How do you ‘sudo’ via the UI ?
parkerc
 
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

Postby Chrisdb » 2020-02-29 20:17

What desktop environment are you using? Gnome, xfce, ...

Anyway, the easiest way is to use the terminal and copy the file with 'sudo'.
Chrisdb
 
Posts: 273
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

Postby parkerc » 2020-02-29 20:53

I’m just using the standard (out of the box) desktop, sorry not sure what that is called..

I have now managed to copy the file over via the command line using..

Code: Select all
 sudo cp /home/me/Documents/up-vpn.sh /etc/NetworkManager/dispatcher.d/


However after a few reboots, it’s still not auto firing the VPN?

Any ideas? Is there anything else I need to do ?
Last edited by parkerc on 2020-03-01 10:21, edited 1 time in total.
parkerc
 
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

Postby Chrisdb » 2020-03-01 10:17

What is the output of:
Code: Select all
ls -l /etc/NetworkManager/dispatcher.d/up-vpn.sh


And:
Code: Select all
systemctl status NetworkManager-dispatcher.service


What does the following command say if you run it from the terminal:
Code: Select all
sudo nmcli connection up id nl2-nodecentral-udp-udp
Chrisdb
 
Posts: 273
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

Postby parkerc » 2020-03-01 10:26

Chrisdb wrote:What is the output of:
Code: Select all
ls -l /etc/NetworkManager/dispatcher.d/up-vpn.sh



-rwxr-xr-x 1 root root 430 Feb 29 20:25 /etc/NetworkManager/dispatcher.d/up-vpn.sh

Chrisdb wrote:What is the output of:
And:
Code: Select all
systemctl status NetworkManager-dispatcher.service



● NetworkManager-dispatcher.service - Network Manager Script Dispatcher Service
Loaded: loaded (/lib/systemd/system/NetworkManager-dispatcher.service; enabled; vendor preset: enabled)
Active: inactive (dead)

Chrisdb wrote:What is the output of:
What does the following command say if you run it from the terminal:
Code: Select all
sudo nmcli connection up id nl2-nodecentral-udp-udp


Error: Connection activation failed: Connection 'nl2-nodecentral-udp-udp' is already active
parkerc
 
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

Postby parkerc » 2020-03-01 10:44

I’ve just turned the vpn off and run the last command again
Code: Select all
 sudo nmcli connection up id nl2-nodecentral-udp-udp

A password is required to connect to 'nl2-nodecentral-udp-udp'.
Warning: password for 'vpn.secrets.password' not given in 'passwd-file' and nmcli cannot ask without '--ask' option.
Error: Connection activation failed: No valid secrets


The link originally shared gives me a couple of options

https://wiki.archlinux.org/index.php/Ne ... stablished

Trying to connect with the above script may still fail with NetworkManager-dispatcher.service complaining about 'no valid VPN secrets', because of the way VPN secrets are stored. Fortunately, there are different options to give the above script access to your VPN password.

1: One of them requires editing the VPN connection configuration file to make NetworkManager store the secrets by itself rather than inside a keyring that will be inaccessible for root: open up /etc/NetworkManager/system-connections/name of your VPN connection and change the password-flags and secret-flags from 1 to 0.

If that alone does not work, you may have to create a passwd-file in a safe location with the same permissions and ownership as the dispatcher script,

2: Alternatively, change the password-flags and put the password directly in the configuration file adding the section vpn-secrets:


Any recommendations?
parkerc
 
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

Postby Chrisdb » 2020-03-01 11:05

The choice is up to you, but if you're the only one using this system, I would use option 2 as it is easier tot accomplish
Chrisdb
 
Posts: 273
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

Postby parkerc » 2020-03-01 13:01

Do you have any Idea why I have to store my credentials again, when I already have the username and password for the nl2.nodecentral-utp-utp VPN configuration stored in the Network Manager UI under ‘Identity’ ?

Looking under the NetworkManager/system-connections/ folder I have two connections listed.

nl2.nodecentral-utp-utp.nmconnection
Wiredconnection1


They look like they relate to the two connections I have listed on the Network Manager UI?
Unfortunately I can’t open the nmconnection file via the UI, it states that the file is of an unknown file type, but could the user/password be in there?
parkerc
 
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

Postby Chrisdb » 2020-03-01 14:12

If it doesn't work by using the GUI, check the file contents through your terminal.

What is the value of 'password-flags' and 'secret-flags'?

If both are set to '0', follow the guide from the arch Wiki you mentioned before:
create a passwd-file in a safe location (/path/to/passwd-file) with the same permissions and ownership as the dispatcher script, containing the following:
Code: Select all
vpn.secrets.password:YOUR_PASSWORD

Your script must be changed accordingly, so that it gets the password from the file:
Code: Select all
...
nmcli connection up id "$VPN_NAME" passwd-file /path/to/passwd-file
...

Chrisdb
 
Posts: 273
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

Postby parkerc » 2020-03-01 17:02

Thanks for all your help on this.

Opening the nl2-nodecentral-udp-udp.nmconnection file in nano I can see under the [vpn] section the flag is set to 1

Code: Select all
[vpn]
password-flags=1


So using option 2, I’ll need to add the following new [vpn-secrets] section into the nl2-nodecentral-udp-udp.nmconnection file

Code: Select all
[vpn-secrets]
password=your_password


Sound correct to you , as I’ve tried the above, and also did a reboot or two, but the VPN is still not starting automatically ?
parkerc
 
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

Postby Chrisdb » 2020-03-01 18:43

Rerun the 'nmcli' command manually again (after reboot) and post the output
Code: Select all
sudo nmcli connection up id nl2-nodecentral-udp-udp


Also please post your final up-vpn.sh file again

EDIT:
You did change the password-flags to 0?
Chrisdb
 
Posts: 273
Joined: 2018-04-10 07:16

Re: Automatically start vpn on boot up ?

Postby parkerc » 2020-03-01 19:29

Chrisdb wrote:Rerun the 'nmcli' command manually again (after reboot) and post the output
You did change the password-flags to 0?


No, let me try that...
parkerc
 
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

Postby parkerc » 2020-03-01 19:40

Chrisdb wrote:Rerun the 'nmcli' command manually again (after reboot) and post the output
Code: Select all
sudo nmcli connection up id nl2-nodecentral-udp-udp


Also please post your final up-vpn.sh file again

EDIT:
You did change the password-flags to 0?

I’ve rebooted the VM , logged in again but the VPN did not start automatically.. :(

When I rerun the following command, via the terminal...

Code: Select all
 sudo nmcli connection up id nl2-nodecentral-udp-udp


it gave me this message..

Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2


So the up-vpn script seems to work, the issue is getting it to automatically run once i’m logged in ?
parkerc
 
Posts: 22
Joined: 2020-02-22 09:19

Re: Automatically start vpn on boot up ?

Postby Chrisdb » 2020-03-01 20:02

Also please post your final up-vpn.sh file again
:roll:

Look at the journal:
Code: Select all
sudo journalctl -u NetworkManager-dispatcher.service
Chrisdb
 
Posts: 273
Joined: 2018-04-10 07:16

PreviousNext

Return to General Questions

Who is online

Users browsing this forum: cooler01 and 5 guests

fashionable