ProtonVPN at startup on Linux
<p>
ProtonVPN is a great service. In this article I will show you how to configure it to run at startup on Linux machines. This is ideal for
<a class="wikilink" href="/raspberry_pi/">
Raspberry Pi
</a>
which you want to keep secured.
</p>
<p>
<strong>
NOTE
</strong>
: ProtonVPN-CLI does not work on a headless Linux installation (Updated: 10-January-2022). The best way forward is to use
<a href="https://github.com/Rafficer/linux-cli-community">
the community version
</a>
. The following steps are based on it and not on the official solution.
</p>
<p>
<a href="https://protonvpn.com/">
ProtonVPN
</a>
is a great VPN solution which includes also a free tier. Some months ago they've released an updated version of their
<a href="https://protonvpn.com/support/linux-vpn-tool/">
command-line tool
</a>
which allows you to connect to the ProtonVPN servers directly. However, this new version is not compatible out-of-the-box with the previous version. It gave me a lot of headaches to find a way to run it automatically at startup on my Raspberry Pi.
</p>
<p>
If you want to run something at startup, the best idea is to run it as a service. This gives you a lot of control regarding when to run it, how to stop it, etc. After you followed the installation instructions on the website, you will need to define a new service, which starts after the network connection has been established. It will also need to run as
<code>
sudo
</code>
, or it will fail to start (running as root user does not work on Ubuntu/Debian systems). The first step is to know where the protonvpn command was installed on your system:
</p>
<pre class="codehilite"><code class="language-bash">which protonvpn
</code></pre>
<p>
The output should be something like:
<code>
/usr/local/bin/protonvpn
</code>
, but if it is not, pay attention and change it in the code block below.
</p>
<p>
Create a file
<strong>
protonvpn.service
</strong>
in the folder
<code>
/etc/systemd/system/
</code>
, and add the following:
</p>
<pre class="codehilite"><code class="language-bash">[Unit]
Description=ProtonVPN-CLI auto-connect
Wants=network-online.target
[Service]
Type=forking
ExecStart=/usr/local/bin/protonvpn c -f
Environment=PVPN_WAIT=300
Environment=PVPN_DEBUG=1
Environment=SUDO_USER=user
[Install]
WantedBy=multi-user.target
</code></pre>
<p>
Remember to change the line
<code>
Environment=SUDO_USER=user
</code>
with the appropriate user name, for example
<code>
pi
</code>
, etc. Also, if you want to change the type of connection, you should edit the line starting with
<code>
ExecStart
</code>
with whatever command you would like to run.
</p>
<p>
Once you have it, you just need to enable it and start it:
</p>
<pre class="codehilite"><code class="language-bash">sudo systemctl daemon-reload
sudo systemctl enable protonvpn
sudo systemctl start protonvpn
</code></pre>
<p>
You can check the status of proton vpn in two different ways, by monitoring the status of the service or by using the command line tool itself:
</p>
<pre class="codehilite"><code class="language-bash">sudo systemctl status protonvpn
protonvpn status
</code></pre>
<p>
If you ever want to stop or restart the service, you can do:
</p>
<pre class="codehilite"><code class="language-bash">sudo systemctl restart protonvpn
sudo systemctl stop protonvpn
</code></pre>
<p>
Note that solutions based on
<code>
cron
</code>
tend not to work properly, since they tend to run before the network becomes active, and thus the command will fail.
</p>
Comment
Share your thoughts on this note. Comments are not public, they are
messages sent directly to my inbox.