How to set up WireGuard® on Raspberry Pi

Introduction

This guide will walk you through the process of setting up a manual WireGuard® connection to Surfshark's servers on your Raspberry Pi. This method allows you to leverage the speed and security of the WireGuard® protocol for a secure and private internet connection while being connected to a Surfshark server.

Before you start

Before you begin the setup process, you will need the following:

  • A Raspberry Pi with an operating system installed (e.g., Raspberry Pi OS).
  • An active Surfshark subscription.
  • Access to the terminal or command line on your Raspberry Pi.

Here's what to do

Step 1: Install WireGuard®

First, you need to install the WireGuard® package on your Raspberry Pi.

  1. Open the terminal on your Raspberry Pi.
  2. Update your package list to ensure you get the latest version:

    sudo apt update
  3. Install the WireGuard tools:

    sudo apt install wireguard -y

Step 2: Get Surfshark Configuration and Keys

Next, you will generate your keys and download the server configuration file directly from your Surfshark account.

  1. Log in to your Surfshark account on the Surfshark website.
  2. Navigate to VPN > Manual setup > Router > WireGuard®.
  3. Click on "I don't have a key pair."
  4. Give your key pair a name and click "Generate a new key pair". The Surfshark website will display your Public and Private keys.
  5. Select a server location you wish to connect to and click "Download". This button will download a configuration file that includes your private key and the server's public key.

Step 3: Configure WireGuard® on Raspberry Pi

Now you will move the downloaded configuration file to the correct directory on your Raspberry Pi.

  1. Transfer the downloaded configuration file (e.g., surfshark.conf) to your Raspberry Pi. You can use a USB drive or a network transfer method like scp.
  2. Open the terminal on your Raspberry Pi.
  3. Move the configuration file to the WireGuard® directory (for example, we select the Sweden Stockholm location, so the downloaded file name is se-sto.conf):

    sudo mv /path/to/your/se-sto.conf /etc/wireguard/surfshark.conf

    NOTE: Replace /path/to/your/surfshark.conf with the actual path to the file you transferred.

Step 4: Connect and Disconnect

You can now start the WireGuard® connection.

  1. To bring the connection up, use the wg-quick command:

    sudo wg-quick up surfshark
  2. To verify the connection is active and check the status, run:

    sudo wg
  3. To disconnect from the server, bring the interface down:

    sudo wg-quick down surfshark

Additional tips

  • To make your Raspberry Pi automatically connect to the VPN when it starts, you can enable the wg-quick service:

    sudo systemctl enable wg-quick@surfshark

    NOTE: After wg-quick@, you must write the configuration file stored in etc/wireguard/ without the .conf at the end. In this tutorial, it is named surfshark.conf

  • After connecting, you use this command in a terminal to confirm that your public IP address has changed to the VPN server's location:

    curl ipecho.net/plain

 

Was this article helpful?
Thank you for your feedback!