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
- Admin addresses live on 10.100.0.0/24
- The public SSH allow stays until you run the bastion step yourself
- Database and dashboard ports are not part of the public firewall change
- Keys are generated on the host and not printed into this file
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."