PortGate

Blueprints · Server Hardening

Zero-Trust 25 min · WireGuard

WireGuard private mesh and bastion access

Creates a 10.100.0.0/24 interface for admin access. Moving sshd onto that interface is a separate script so a failed handshake cannot remove public SSH.

Live config

Baked-in protections

Step 1 · bash

Install WireGuard

/root/portgate-blueprints/wireguard-install.sh

Generates a key if one is not already present. Add the peer public key before you expect a handshake.

#!/bin/sh
set -eu
apt-get update
apt-get install -y wireguard
umask 077
[ -f /etc/wireguard/privatekey ] || wg genkey | tee /etc/wireguard/privatekey | wg pubkey > /etc/wireguard/publickey
chmod 600 /etc/wireguard/privatekey
echo "This host public key:"
cat /etc/wireguard/publickey

Step 2 · ini

wg0 interface

/etc/wireguard/wg0.conf

Replace the private key path after the install step. The peer block is omitted when WG_PEER_KEY is empty.

[Interface]
Address = 10.100.0.1/24
ListenPort = 51820
PrivateKey = REPLACE_WITH_CONTENTS_OF_/etc/wireguard/privatekey
SaveConfig = false

[Peer]
PublicKey = 
AllowedIPs = 10.100.0.2/32

Step 3 · bash

Move SSH to the tunnel

/root/portgate-blueprints/wireguard-ssh.sh

Do not run this until wg0 is up and you have logged in over 10.100.0.0/24 from a second session.

#!/bin/sh
set -eu
wg show wg0
cat > /etc/ssh/sshd_config.d/98-wireguard-listen.conf <<'EOF'
ListenAddress 10.100.0.1
EOF
sshd -t
echo "Reload sshd only after this session is already connected over WireGuard."