Harden SSH: disable passwords, forwarding, add keepalive

Add SSH hardening to user_data for future server rebuilds:
- PasswordAuthentication no (key-only access)
- X11Forwarding no (headless server)
- AllowTcpForwarding no (no SSH tunnels needed)
- AllowAgentForwarding no (no agent forwarding needed)
- MaxAuthTries 3 (reduced from 6)
- ClientAliveInterval 300 + ClientAliveCountMax 2 (clean up dead sessions)

Already applied manually to the existing server via
/etc/ssh/sshd_config.d/99-hardening.conf.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ullrich Schäfer 2026-03-29 22:32:30 +02:00
parent 7d63e2b754
commit 8eb3481831
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9

View file

@ -41,6 +41,18 @@ resource "hcloud_server" "trails" {
# Create app directory
mkdir -p /opt/trails-cool
# Harden SSH
cat > /etc/ssh/sshd_config.d/99-hardening.conf <<'SSHD'
PasswordAuthentication no
X11Forwarding no
AllowTcpForwarding no
AllowAgentForwarding no
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
SSHD
systemctl reload ssh
EOF
}