PortGate

Blueprints · Server Hardening

Zero-Trust 25 min · Ubuntu 24.04 / Debian 12

Ubuntu 24.04 / Debian 12 zero-trust initial server hardening

Creates a sudo user, refuses to change sshd until that user has a public key, then enables UFW, Fail2Ban, unattended upgrades, sysctl network hardening, and the PortGate agent.

Live config

Baked-in protections

Step 1 · bash

User and SSH

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

The script exits before it changes sshd if the sudo user has no public key.

#!/bin/sh
set -eu
if [ "$(id -u)" -ne 0 ]; then
  echo "Run this script as root." >&2
  exit 1
fi
id "deploy" >/dev/null 2>&1 || useradd --create-home --shell /bin/bash "deploy"
usermod -aG sudo "deploy"
install -d -m 700 -o "deploy" -g "deploy" "/home/deploy/.ssh"
touch "/home/deploy/.ssh/authorized_keys"
chown "deploy:deploy" "/home/deploy/.ssh/authorized_keys"
chmod 600 "/home/deploy/.ssh/authorized_keys"
if [ -n "" ]; then
  grep -qxF "" "/home/deploy/.ssh/authorized_keys" || printf '%s\n' "" >> "/home/deploy/.ssh/authorized_keys"
fi
if [ ! -s "/home/deploy/.ssh/authorized_keys" ]; then
  echo "Stop. deploy has no SSH public key. Add one before disabling password login or you will lose SSH access. sshd was not changed." >&2
  exit 1
fi
cat > /etc/ssh/sshd_config.d/99-portgate.conf <<'EOF'
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
EOF
sshd -t
systemctl reload ssh 2>/dev/null || systemctl reload sshd

Step 2 · bash

Firewall, Fail2Ban, upgrades, and sysctl

/root/portgate-blueprints/ubuntu-firewall.sh

Opens SSH before enabling UFW. Port 22 is allowed, not denied.

#!/bin/sh
set -eu
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y ufw fail2ban unattended-upgrades
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'EOF'
[sshd]
enabled = true
port = ssh
maxretry = 5
bantime = 1h
EOF
systemctl enable --now fail2ban
cat > /etc/apt/apt.conf.d/52portgate-unattended <<'EOF'
Unattended-Upgrade::Automatic-Reboot "false";
EOF
systemctl enable --now unattended-upgrades
cat > /etc/sysctl.d/99-portgate.conf <<'EOF'
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
EOF
sysctl --system

Step 3 · bash

Install the PortGate agent

/root/portgate-blueprints/ubuntu-agent.sh

Uses --mode all. The token must include server, AI telemetry, and malware abilities.

#!/bin/sh
set -eu
# The token needs server:ingest, ai:telemetry, and malware:scan.
curl -fsSL "https://example.com/downloads/install.sh" | sh -s -- --token "paste-from-dashboard" --mode all --url "https://example.com"