Key-Only OpenSSH and Journal-Backed fail2ban on Public Linux Hosts

2026-09-29·3 min read

A freshly assigned public IPv4 address typically attracts several thousand SSH authentication attempts within its first twelve hours online. Even with strong random passwords, leaving password authentication enabled invites credential stuffing and rapidly bloats /var/log/auth.log.

1. Verify Key Login Before Touching sshd_config

On Ubuntu 24.04, drop-in files in /etc/ssh/sshd_config.d/ are evaluated before the rest of /etc/ssh/sshd_config, and OpenSSH applies first-match-wins semantics. Always inspect effective settings with sshd -T and confirm your key works in a separate session before disabling passwords:

cat > /etc/ssh/sshd_config.d/00-root-login.conf <<'EOF'
PermitRootLogin prohibit-password
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
MaxAuthTries 4
EOF
sshd -t && systemctl reload ssh

2. Adding Lightweight fail2ban with the systemd Backend

Key-only authentication eliminates password guessing at the protocol level, while fail2ban keeps persistent scanners from burning file descriptors and journal space:

cat > /etc/fail2ban/jail.d/sshd-local.conf <<'EOF'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 5
findtime = 10m
bantime = 1h
EOF
systemctl enable --now fail2ban

Using backend = systemd reads directly from journald without log-rotation race conditions and stays under 25 MB RSS.