WireGuard

From The Incoherency.Net Wiki
Revision as of 15:31, 26 July 2026 by Denis (talk | contribs) (Created page with "= WireGuard = == Key Management (wg) == The `wg` utility provides everything required to generate and manage WireGuard key material. === Generate a Private Key === Generate a new private key: <pre> wg genkey </pre> Save it to a file: <pre> wg genkey > private.key </pre> === Derive a Public Key === A WireGuard public key is always derived from the private key. Generate the corresponding public key: <pre> wg pubkey < private.key </pre> Save it: <pre> wg pubkey...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

WireGuard

[edit]

Key Management (wg)

[edit]

The `wg` utility provides everything required to generate and manage WireGuard key material.

Generate a Private Key

[edit]

Generate a new private key:

wg genkey

Save it to a file:

wg genkey > private.key

Derive a Public Key

[edit]

A WireGuard public key is always derived from the private key.

Generate the corresponding public key:

wg pubkey < private.key

Save it:

wg pubkey < private.key > public.key

Generate a Key Pair

[edit]

Generate both the private and public key in one command:

wg genkey | tee private.key | wg pubkey > public.key

Generate a Preshared Key (PSK)

[edit]

Generate a new preshared key:

wg genpsk

Save it:

wg genpsk > psk.key

Notes

[edit]
  • Every WireGuard interface has a single private/public key pair.
  • Every peer has its own public key.
  • A PresharedKey is optional and unique per peer.
  • Public keys are deterministic and can always be regenerated from the private key.
  • Only the private key must remain secret.
  • Public keys are safe to share.
  • PSKs must be configured identically on both peers.