Back to FAQ

How to Configure Portwarp CLI to Start Automatically on Boot (Linux) - (Updated)

Portwarp Team /

If you are running Portwarp on a Linux distribution that uses systemd
(such as Ubuntu, Debian, Fedora, or Arch Linux), you can configure Portwarp to
start at boot and keep running as a service.

After completing this guide:

  • Portwarp starts automatically whenever the system boots.
  • All of your enabled tunnels reconnect in the background.
  • systemd restarts Portwarp if the daemon exits unexpectedly, then reconnects
the enabled tunnels.
Requirements

- A Linux distribution with systemd
- Portwarp CLI installed
- Logged in with pwrp login as the Linux user that will run the service

Before creating the service, verify that the CLI can connect your tunnels as
that user:

bash
pwrp connect --all --detach
pwrp ps

Stop those test sessions before continuing:

bash
pwrp stop --all

Step 1: Create the service file

Create a templated service file:

bash
sudo nano /etc/systemd/system/[email protected]

The @ is important: it lets the service run as the Linux user supplied when
it is enabled. In this guide, %i means that service-instance username; it is
not a tunnel name.


Step 2: Paste the service configuration

Paste the following into the file:

ini
[Unit]
Description=Portwarp tunnels for %i
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=%i
Environment=HOME=/home/%i
WorkingDirectory=/home/%i

# Start the daemon, wait until its local socket is ready, then connect every
# enabled tunnel. The shell remains running while the daemon is running, so
# systemd can restart the whole service if the daemon exits.
ExecStart=/bin/sh -c '/usr/local/bin/pwrp daemon & daemon_pid=$!; until [ -S "$HOME/.portwarp/daemon.sock" ]; do sleep 0.1; done; /usr/local/bin/pwrp connect --all --detach || { kill "$daemon_pid"; wait "$daemon_pid"; exit 1; }; wait "$daemon_pid"'
Restart=on-failure
RestartSec=5

StandardOutput=journal
StandardError=journal
SyslogIdentifier=pwrp

[Install]
WantedBy=multi-user.target

If which pwrp reports a path other than /usr/local/bin/pwrp, replace both
occurrences of /usr/local/bin/pwrp in ExecStart with that path.

Save the file and exit your editor. In Nano, press Ctrl+O, Enter, then
Ctrl+X.


Step 3: Reload systemd

Tell systemd to reload its service definitions:

bash
sudo systemctl daemon-reload

Step 4: Enable the service

Enable the service for your current Linux user so it starts automatically after
every boot:

bash
sudo systemctl enable pwrp@$(whoami)

Step 5: Start the service

Start Portwarp now, without waiting for the next reboot:

bash
sudo systemctl start pwrp@$(whoami)

Verify it is running

Check the service and its tunnel sessions:

bash
sudo systemctl status pwrp@$(whoami)
pwrp ps

To follow the service logs:

bash
sudo journalctl -u pwrp@$(whoami) -f

Done

Portwarp now starts automatically at boot and connects every enabled tunnel.

To connect only selected tunnels instead, replace --all in the ExecStart
line with their exact tunnel IDs or names, for example:

bash
pwrp connect 6fc2dc65 "Minecraft Java" --detach

After changing the service file, run:

bash
sudo systemctl daemon-reload
sudo systemctl restart pwrp@$(whoami)