PortGate

Blueprints · Server Hardening

Production 25 min · RHEL 9 / AlmaLinux 9 / Rocky Linux 9

RHEL 9 / AlmaLinux 9 / Rocky Linux 9 production hardening

Opens SSH, HTTP, and HTTPS in firewalld, keeps SELinux enforcing when it is already enabled, switches sshd to key-only after a public key exists, and turns on dnf-automatic security updates.

Live config

Baked-in protections

Step 1 · bash

User and key-only SSH

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

Same lockout guard as the Debian bootstrap. The drop-in is written only after the key file is non-empty.

#!/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 wheel "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. 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 sshd

Step 2 · bash

firewalld, SELinux, and dnf-automatic

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

Does not enable SELinux when the kernel has it disabled. A disabled SELinux host needs a planned reboot, not a live flip.

#!/bin/sh
set -eu
dnf install -y firewalld dnf-automatic
systemctl enable --now firewalld
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
if [ "$(getenforce)" = "Permissive" ]; then
  setenforce 1
fi
if [ "$(getenforce)" != "Disabled" ]; then
  sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config
else
  echo "SELinux is disabled in the kernel. The config file was left unchanged."
fi
cat > /etc/dnf/automatic.conf <<'EOF'
[commands]
upgrade_type = security
apply_updates = yes
reboot = never
EOF
systemctl enable --now dnf-automatic.timer

Step 3 · bash

Install the PortGate agent

/root/portgate-blueprints/rhel-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"