# WireGuard from scratch on a Linux VPS

> Install WireGuard, generate keys, write interface configs, and bring up a single peer tunnel on a Linux VPS.

Source: https://fullbytedeveloper.com/blog/wireguard-from-scratch-linux-vps
Published here: 2026-12-03, updated 2026-12-03

WireGuard builds encrypted tunnels with public keys and a short config surface [1]. This walkthrough stands up one VPS peer and one client peer from the official quick start shape [1]. Glossary first if needed: [what is a VPN](/blog/what-is-a-vpn). Product tradeoffs: [WireGuard vs Tailscale vs OpenVPN](/blog/wireguard-vs-tailscale-vs-openvpn).

## Quick start (under a minute)

On any Linux machine with `wireguard-tools` installed per the install page [2]:

```bash
umask 077
wg genkey | tee privatekey | wg pubkey > publickey
wc -c privatekey publickey
```

You should see two small key files (roughly 45 bytes each with newline) and nonzero byte counts. Never paste the private key into chat or email [1].

WireGuard tools were not available on this draft host, so the byte counts below are not measured here. Run the block on your VPS and client after install [2].

## Draw one server peer and one client peer

<figure aria-label="VPS WireGuard peer and client peer with UDP handshake and tunnel addresses">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 360 240" role="img" aria-hidden="true">
  <defs>
    <marker id="wireguardfromscratchlinu-wg-arr" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto">
      <path d="M0,0 L8,4 L0,8 Z" fill="#14b8a6"/>
    </marker>
  </defs>
  <rect x="0" y="0" width="360" height="240" rx="12" fill="#0b1f3a"/>
  <rect x="115.714" y="11" width="128.571" height="90" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="1.28571"/>
  <text x="180" y="44" text-anchor="middle" font-size="12" font-weight="600" fill="#e6edf7" font-family="system-ui,sans-serif">VPS wg0 [1]</text>
  <text x="180" y="62" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">10.0.0.1/24 ListenPort 51820</text>
  <text x="180" y="78" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">peer = client pubkey</text>
  <rect x="25.7143" y="139" width="128.571" height="90" rx="4" fill="#123052" stroke="#14b8a6" stroke-width="1.28571"/>
  <text x="90" y="172" text-anchor="middle" font-size="12" font-weight="600" fill="#e6edf7" font-family="system-ui,sans-serif">client wg0 [1]</text>
  <text x="90" y="190" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">10.0.0.2/24</text>
  <text x="90" y="206" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">Endpoint VPS:51820</text>
  <path d="M240 170 Q 280 120 280 92" fill="none" stroke="#14b8a6" stroke-width="0.964286" marker-end="url(#wireguardfromscratchlinu-wg-arr)"/>
  <path d="M320 92 Q 320 120 240 170" fill="none" stroke="#14b8a6" stroke-width="0.964286" marker-end="url(#wireguardfromscratchlinu-wg-arr)"/>
  <text x="231.429" y="128" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">UDP + handshake</text>
  <text x="180" y="230" text-anchor="middle" font-size="12" fill="#e6edf7" font-family="system-ui,sans-serif">AllowedIPs routes prefixes into tunnel [1]</text>
</svg>
</figure>

Each side lists the other's public key under `[Peer]`. Inner tunnel addresses live on `[Interface]` [1].

## Install tools, then generate keys

Install WireGuard for your distribution from the installation page [2]. Repeat key generation on the VPS and on the client:

```bash
umask 077
wg genkey | tee privatekey | wg pubkey > publickey
```

You should have `privatekey` readable only by your user and `publickey` safe to copy into peer blocks [1]. Exchange public keys out of band you trust.

## Write matching interface configs

Minimal VPS `wg0.conf` aligned with the quick start [1]:

```ini title="/etc/wireguard/wg0.conf on VPS"
[Interface]
PrivateKey = <vps-private>
Address = 10.0.0.1/24
ListenPort = 51820

[Peer]
PublicKey = <client-public>
AllowedIPs = 10.0.0.2/32
```

Client mirror [1]:

```ini title="wg0.conf on laptop"
[Interface]
PrivateKey = <client-private>
Address = 10.0.0.2/24

[Peer]
PublicKey = <vps-public>
Endpoint = <vps-public-ip>:51820
AllowedIPs = 10.0.0.0/24
PersistentKeepalive = 25
```

`AllowedIPs` decides which destination IPs ride the tunnel toward that peer [1]. Start with tunnel-only prefixes before you route all traffic with `0.0.0.0/0`. `PersistentKeepalive = 25` matches the quick start guidance for clients behind NAT [1].

Restrict file permissions on configs that hold private keys. `wg-quick` expects root for `up`/`down` on most systems.

## Bring the interface up and verify

```bash
sudo wg-quick up wg0
sudo wg show
ping -c 3 10.0.0.1
```

Per the quick start, `wg show` should list the interface, listening port, peer public key, and a recent handshake after traffic flows [1]. Example shape (values will differ on your machine):

```text
interface: wg0
  public key: <vps-public>
  private key: (hidden)
  listening port: 51820

peer: <client-public>
  allowed ips: 10.0.0.2/32
  latest handshake: 1 minute ago
```

Open UDP `51820` (or your chosen port) in the VPS provider firewall and any host firewall. If clients must use the VPS as an internet exit, enable IPv4 forwarding and SNAT on the VPS. Those distro-specific steps are outside this quick start; keep them in version control when you add them.

Tear down safely:

```bash
sudo wg-quick down wg0
```

## Rotate keys without renaming the universe

WireGuard identifies peers by public keys, not by DNS names inside the tunnel [1]. When you rotate a laptop key, update only the `[Peer]` public key on the VPS and the matching private key on the client. Inner IPs (`10.0.0.2/32`) can stay put if the same machine keeps that role.

Document which key belongs to which device in your password manager or inventory. The config file is short precisely because it does not carry X.509 subject lore.

## Split tunnel versus full tunnel on AllowedIPs

`AllowedIPs` on the client decides which destination prefixes enter the tunnel [1]. A split setup lists only RFC1918 lab nets or a single /32 for one service. A full-tunnel setup lists `0.0.0.0/0` and `::/0` so general internet egress exits through the VPS. That second pattern turns the VPS into a router with legal and abuse implications at your provider. Choose deliberately and log the choice in your runbook.

Server-side `AllowedIPs` on the VPS peer entry is usually the client's tunnel address (/32) so the server knows which ciphertext belongs to which inner IP.

## Firewall checklist before you blame WireGuard

When `wg show` never records a handshake, walk this ordered list:

| Check | What to verify |
|---|---|
| UDP port | Provider security group allows your `ListenPort` |
| Correct endpoint | Client `Endpoint` IP matches current VPS public IP |
| Keys swapped | Each side pasted the other's public key, not its own |
| Time sync | Large clock skew is rare but NTP helps logs make sense |
| Local firewall | `ufw` or `nftables` on VPS allows UDP in |

ICMP ping across tunnel inner IPs is a sanity check after handshake appears [1]. It does not prove UDP crypto is configured for every app you care about.

## When you want mesh instead of hand-written peers

Hand-written `[Peer]` blocks scale poorly when every laptop talks to every server. Mesh products add identity, NAT traversal, and ACLs. Tailscale is one path documented on this site: [Tailscale for agent machines](/blog/tailscale-for-agent-machines). Stay on raw WireGuard when you want full control of keys, routes, and audit on a single VPS.

## Log enough to audit later

Keep a dated note of which public key belongs to which device, the VPS public IP, and whether you enabled full-tunnel routing [1]. When an employee laptop disappears, you remove its peer block and reload the interface. WireGuard does not ship a central audit UI; your version control and firewall logs fill that gap.

Store private keys only on the devices that need them. Backup configs without private keys if you must archive structure, but rotate after incidents.

Mobile clients import the same `[Interface]` / `[Peer]` text through OS-specific WireGuard apps; the cryptography matches Linux [1]. The quick start remains the reference for key generation even when the UI wraps `wg-quick` differently.

IPv6 inner addresses work the same way with `/64` or /128 assignments when your provider routes them. Dual-stack clients list both `0.0.0.0/0` and `::/0` in `AllowedIPs` only when you intend full-tunnel egress for both families [1].

## Failure modes worth naming

Treating WireGuard like OpenVPN file soup. WireGuard configs are short and key-centric [1].

Pasting private keys into tickets or screenshots. Rotate if leaked.

Forgetting UDP in the cloud firewall while TCP SSH still works. The tunnel never establishes.

Setting `AllowedIPs = 0.0.0.0/0` on the client before you understand split tunneling. You can send all traffic through the VPS on purpose, but that is a routing decision [1].

Skipping `PersistentKeepalive` on NATed clients and blaming WireGuard for idle disconnects [1].

Encryption replaces application auth. WireGuard gives you a private channel, not user login.

Bring `wg0` up on the VPS and client, then `ping` across the tunnel before you open SSH to the world. If the word VPN still feels fuzzy, [what is a VPN](/blog/what-is-a-vpn) names the threat model this tunnel fits into. When you wonder whether hand-edited peers are worth the hassle, [WireGuard vs Tailscale vs OpenVPN](/blog/wireguard-vs-tailscale-vs-openvpn) lays out the product trade space without pretending one logo fits every team.

Send this to the friend about to expose SSH to the world instead of a tunnel.

Image: Concept illustration of VPS and client peers exchanging UDP handshake packets across WireGuard tunnel addresses, no people and no readable UI text.
https://fullbytedeveloper.com/media/wireguard-from-scratch-linux-vps/wireguard-from-scratch-linux-vps-venice.webp
Each peer lists the other's public key; UDP carries encrypted tunnel packets.

## Sources

1. [WireGuard: Quick Start, accessed 2026-12-03](https://www.wireguard.com/quickstart/)
2. [WireGuard: Installation, accessed 2026-12-03](https://www.wireguard.com/install/)
3. [Full Byte Developer: What is a VPN](https://fullbytedeveloper.com/blog/what-is-a-vpn)
4. [Full Byte Developer: WireGuard vs Tailscale vs OpenVPN](https://fullbytedeveloper.com/blog/wireguard-vs-tailscale-vs-openvpn)
5. [Full Byte Developer: Tailscale for agent machines](https://fullbytedeveloper.com/blog/tailscale-for-agent-machines)
