Client Setup

Client Setup

After setup.sh runs on the server, ./scripts/setupclient.sh and ./scripts/setupclient.ps1 are ready to distribute. The scripts are idempotent: if a WireGuard config already exists on the client, they bring up the existing tunnel and exit.

What Happens

  1. The script generates a WireGuard X25519 keypair locally — the private key never leaves the device.
  2. It sends only the public key plus X-Auth-Token to https://<SERVER>/addnewpeer.
  3. The server responds with a WireGuard config containing <PASTE_YOUR_PRIVATE_KEY_HERE>.
  4. The script substitutes the placeholder with the locally-generated private key.
  5. The config is written to disk and the tunnel is started.

Linux

Prerequisites

sudo apt install wireguard-tools curl python3

On RHEL/Fedora:

sudo dnf install wireguard-tools curl python3

Run

chmod +x setupclient.sh
sudo ./setupclient.sh

What It Does

  1. Checks that wg, curl, and python3 are in PATH; requires root.
  2. If /etc/wireguard/wg0.conf already exists → runs wg-quick up wg0 and exits.
  3. Generates keypair: wg genkey → private key; echo privkey | wg pubkey → public key.
  4. Registers with the server:
    curl -sk -X POST \
      -H "Content-Type: application/json" \
      -H "X-Auth-Token: <token>" \
      -d '{"public_key": "<pubkey>"}' \
      https://<SERVER_IP>/addnewpeer
  5. Parses the JSON response with python3. Validates status == "ok".
  6. Replaces <PASTE_YOUR_PRIVATE_KEY_HERE> with the private key → writes /etc/wireguard/wg0.conf (mode 600).
  7. Runs wg-quick up wg0 and enables systemctl enable wg-quick@wg0.

Generated Config Structure

[Interface]
PrivateKey = <client-private-key>
Address = 10.13.26.X/32
DNS = 172.29.144.30
 
[Peer]
PublicKey = <server-public-key>
Endpoint = <SERVER_IP>:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

AllowedIPs = 0.0.0.0/0 routes all traffic through the VPN. DNS queries go to Pi-hole at 172.29.144.30.

Manage the Tunnel

sudo wg show wg0
sudo wg-quick down wg0
sudo wg-quick up wg0

Adding More Clients

Run the setup script on any new device. Each run generates a fresh keypair and allocates the next available IP. No server action is required. The pool supports 253 peers (10.13.26.2 through 10.13.26.254).

Manual Peer Removal

There is no automated deregistration. To remove a peer:

rm ./peers/<sha256-prefix>.conf
docker exec wireguard wg set wg0 peer <public-key> remove