Skip to content

Instantly share code, notes, and snippets.

@juxuanu
Last active January 12, 2024 09:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juxuanu/4935b58019eab8d1b596ae8dde70939f to your computer and use it in GitHub Desktop.
Save juxuanu/4935b58019eab8d1b596ae8dde70939f to your computer and use it in GitHub Desktop.
Systemd user service to autoconnect to ProtonVPN through their the CLI utility

Service definition: ~/.config/systemd/user/auto-protonvpn.service

[Unit]
Description=ProtonVPN Connection
After=network-online.target
BindsTo=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/protonvpn-cli ks --off ; /usr/bin/protonvpn-cli connect -f
ExecStop=/usr/bin/protonvpn-cli disconnect ; /usr/bin/protonvpn-cli ks --off
ExecReload=/usr/bin/protonvpn-cli ks --off ; /usr/bin/protonvpn-cli reconnect 
RemainAfterExit=yes
Restart=on-failure
RestartSec=5

[Install]
WantedBy=graphical-session.target

What to do:

  • Make the network-online.target available for the user daemon: systemctl --user link /usr/lib/systemd/system/network-online.target
  • Reload the daemon: systemctl --user daemon-reload
  • Enable the service: systemctl --user enable auto-protonvpn.service

Note: for networks like eduroam, you should connect through TCP (/usr/bin/protonvpn-cli connect -f -p tcp).

Main caveat: no Wireguard support. For that, you need to generate a configuration file (so, no automatic server switching) in https://account.protonvpn.com/downloads and use sudo nmcli con import type wireguard file path/to/wireguard_config.conf to add it permamently.

@kohane27
Copy link

Thank you so much! It works perfectly on my machine!

@RiddermanR
Copy link

I had to add "Requires=dbus-setenv.service" to the install section of the service to make it work.
Ohterwise I got an error "Environment variable DBUS_SESSION_BUS_ADDRESS is unset "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment