Skip to content

Instantly share code, notes, and snippets.

@juxuanu
Last active August 15, 2026 11:11
Show Gist options
  • Select an option

  • Save juxuanu/4935b58019eab8d1b596ae8dde70939f to your computer and use it in GitHub Desktop.

Select an option

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.

@trualf

trualf commented Nov 9, 2024

Copy link
Copy Markdown

Is there a reason why the kill switch is deliberately turned off per command line? I would rather have the kill switch be permanently in place; however, it appears the VPN doesn't automatically (re-)connect when this is active.

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