ProtonVPN / linux-cli

Official ProtonVPN Linux app (CLI)
https://protonvpn.com/download-linux
GNU General Public License v3.0
335 stars 43 forks source link

as root: sudo -u normaluser protonvpn-cli c -f somehow does not work. #38

Closed niva42 closed 2 years ago

niva42 commented 3 years ago

I try to automate the connection to a protonVPN. Every time my laptop (manjaro linux) is connected to the internet it should get connected to protonVPN. (This is done via the systemd unit NetworkManager-dispatcher.service) To do this I need to de-escalate root privileges. But this somehow does not seem to work with protonvpn-cli. When I execute sudo -u normaluser protonvpn-cli c -f I still get the error message: Running ProtonVPN as root is not supported and is highly discouraged ... Isn't that really strange? But probably I am being really stupid. Please tell me if you can!

calexandru2018 commented 3 years ago

Hey @niva42

That is because sudo set the super user environment variable. Why would you use sudo -u normaluser protonvpn-cli c -f anyway ?

niva42 commented 3 years ago

Hello Alexandru!

The systemd unit NetworkManager-dispatcher.service executes scripts in the folder /etc/NetworkManager/dispatcher.d/ after a connection is established. But it does so with root privileges. So I wrote a little script that should connect to protonVPN that should get executed by NetworkManager-dispatcher.service. So I need to de-escalate privileges to a normal user. For this I used sudo -u normaluser protonvpn-cli c -f in this script. Is this dumb? It there a better solution to do this? I was thinking, it might be best to write a user systemd unit. But on the other hand, the NetworkManager-dispatcher.service is exactly made for a case like this.

PS: See https://wiki.archlinux.org/title/NetworkManager#Network_services_with_NetworkManager_dispatcher

calexandru2018 commented 2 years ago

@niva42 place a .service under ~/.config/systemd/user

Actually this has been asked on reddit: https://www.reddit.com/r/ProtonVPN/comments/qbvp8r/autoconnect_linux_script_for_official_cli/