Infrastructure Notes: Tightening SSH Baselines and Alert Noise
Permissive SSH defaults and chatty monitoring rules quietly erode production security and on-call focus. Walk through our baseline Linux hardening checklist using Ed25519 keys, drop-in sshd configs, Fail2Ban recidive jails, and Prometheus Alertmanager routing that cut weekly alerts from 40 to 3.
Whenever I inherit an existing Linux VPS fleet for an infrastructure audit, I almost always uncover the same pair of operational debts within the first ten minutes: root password authentication still listening on port 22 while /var/log/auth.log swells with hundreds of megabytes of botnet brute-force attempts, and an #ops-alerts Slack channel everybody muted months ago because it fires forty false alarms every week. Weak access baselines and noisy monitoring look like separate issues on paper, yet in production they reinforce each other directly. When engineers learn to ignore forty transient alerts a week, they also miss the one genuine intrusion warning or disk-full page buried in the scrollback.
During a recent cleanup across twelve Ubuntu production hosts, we standardized SSH access around Ed25519 keys, moved daemon overrides into clean drop-in configs, jailed repeat scanners for a week at a time, and rebuilt Prometheus Alertmanager routing. Weekly notifications dropped from forty down to three, and every single alert since has required real engineering action.
Moving to Ed25519 Keys and Drop-In sshd Configs
Legacy RSA-2048 keys still authenticate fine, yet Ed25519 keys have been my default baseline for years: public keys are compact (68 characters), signature verification runs in constant time, and -a 100 applies 100 key-derivation rounds to harden local private key passphrases against offline cracking:
ssh-keygen -t ed25519 -a 100 -C "nikhil@ops-bastion-2026" -f ~/.ssh/id_ed25519_prod
Once public keys are installed inside /home/deploy/.ssh/authorized_keys (with strict chmod 700 ~/.ssh, chmod 600 ~/.ssh/authorized_keys, and matching user ownership), avoid editing /etc/ssh/sshd_config directly. Modifying the vendor config triggers interactive dpkg merge prompts during unattended openssh-server security upgrades. Instead, isolate hardening directives inside /etc/ssh/sshd_config.d/99-hardening.conf.
Watch out for a subtle OpenSSH evaluation rule on Ubuntu 22.04 and 24.04 before saving that file: sshd_config uses first-match-wins parsing! Many cloud images create /etc/ssh/sshd_config.d/50-cloud-init.conf containing PasswordAuthentication yes. Because 50-cloud-init.conf sorts alphabetically ahead of 99-hardening.conf, leaving that cloud-init file intact causes OpenSSH to honor PasswordAuthentication yes and silently ignore your no setting later! Always remove or comment out conflicting lines in 50-cloud-init.conf first, write /etc/ssh/sshd_config.d/99-hardening.conf, and verify the effective runtime values with sshd -T:
# /etc/ssh/sshd_config.d/99-hardening.conf
PermitRootLogin no
PubkeyAuthentication yes
AuthenticationMethods publickey
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitEmptyPasswords no
MaxAuthTries 3
MaxStartups 10:30:60
LoginGraceTime 20
ClientAliveInterval 300
ClientAliveCountMax 2
AllowUsers deploy nikhil
X11Forwarding no
AllowAgentForwarding no
AllowTcpForwarding no
Never reload sshd over your only open shell without a safety net. Keep an active root terminal open in Window 1 as your backup rescue session, validate syntax with sshd -t and inspect parsed output with sshd -T, reload the service, and verify a brand-new login with ssh -o IdentitiesOnly=yes in Window 2 before ever closing Window 1:
sshd -t && sshd -T | grep -E '^(permitrootlogin|passwordauthentication|authenticationmethods|allowusers|allowagentforwarding)'
# permitrootlogin no
# passwordauthentication no
# authenticationmethods publickey
# allowusers deploy nikhil
# allowagentforwarding no
systemctl reload ssh
Disabling AllowAgentForwarding matters across multi-server fleets; if a web node ever suffers a privilege breakout like the ones examined in 2026 shared hosting and MCP security incidents, an attacker with root on that machine cannot hijack a forwarded local SSH agent socket to pivot laterally into peer servers; use ProxyJump (ssh -J) from your workstation instead.
Firewall Scoping With UFW and Fail2Ban recidive Jails
Even with password authentication off, leaving port 22 exposed to 0.0.0.0/0 lets internet scanners hammer sshd pre-auth workers continuously and fill journal logs. Whenever a team uses a static office gateway or WireGuard bastion (198.51.100.10/32), restrict port 22 at the host firewall before enabling UFW:
ufw default deny incoming
ufw default allow outgoing
ufw allow from 198.51.100.10/32 to any port 22 proto tcp comment 'WireGuard Bastion SSH'
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
Where roaming administrator access requires keeping SSH reachable publicly, combine ufw limit 22/tcp with Fail2Ban. Standard 1-hour [sshd] bans alone fail against slow distributed botnets that pause 65 minutes for bans to expire and probe again every hour for weeks. Enabling Fail2Ban's built-in recidive jail monitors /var/log/fail2ban.log itself and issues a 7-day firewall block against repeat offenders banned three times within 24 hours.
Create /etc/fail2ban/jail.d/sshd-hardening.local:
[DEFAULT]
banaction = ufw
bantime.increment = true
[sshd]
enabled = true
mode = aggressive
port = ssh
backend = systemd
maxretry = 3
findtime = 10m
bantime = 1h
[recidive]
enabled = true
logpath = /var/log/fail2ban.log
banaction = ufw
bantime = 7d
findtime = 1d
maxretry = 3
Restart and verify active bans with systemctl restart fail2ban && fail2ban-client status sshd. Across our twelve audited servers, auth.log pre-auth disconnect noise dropped by 98% within forty-eight hours, making real anomalous login attempts stand out immediately.
Cutting Weekly Monitoring Alerts From 40 Down to 3
Next, we audited 30 days of monitoring history (~40 alerts per week). Roughly 90% of false alarms came from three configuration mistakes: zero for: hold windows on spiky metrics (so 45-second apt-daily runs paged on CPU), routing every severity into one chat room, and missing dependency inhibition during planned or unplanned host reboots.
We reorganized Prometheus rules and Alertmanager into three strict tiers:
| Severity Label | Delivery Channel | Minimum for: Duration | Example Trigger Condition | Expected Operator Action |
|---|---|---|---|---|
critical | PagerDuty / Phone Wakeup | 2m to 5m | Host unreachable, HTTP 5xx above 2%, FPM socket dead, disk above 92% | Acknowledge and remediate immediately |
warning | Dedicated Slack #ops-warn | 10m to 15m | Disk projected full in 48h, worker pool above 80%, elevated CPU steal | Investigate during current workday |
info | Daily digest / Ticket queue | 30m to 1h | TLS certificate under 21 days, kernel reboot pending | Schedule in weekly maintenance sprint |
Finally, we added inhibit_rules inside /etc/prometheus/alertmanager.yml so root-cause outages automatically mute downstream symptom alerts:
route:
group_by: ['alertname', 'cluster']
group_wait: 30s
group_interval: 5m
repeat_interval: 4h
receiver: 'slack-warnings'
routes:
- matchers:
- severity = "critical"
receiver: 'pagerduty-oncall'
- matchers:
- severity = "info"
receiver: 'daily-ticket-digest'
inhibit_rules:
- source_matchers:
- alertname = "HostDown"
target_matchers:
- alertname != "HostDown"
equal: ['instance']
- source_matchers:
- severity = "critical"
target_matchers:
- severity = "warning"
equal: ['alertname', 'instance']
Those rules ended the classic 3 AM alert storm where one hypervisor reboot pages on-call engineers fourteen separate times for Nginx, PHP-FPM, PostgreSQL, Redis, and exporter targets on the same box. Clean, high-signal alerts also provide trustworthy triggers if you later connect read-only AI triage agents to your Linux monitoring stack.
Baseline Onboarding Checklist
- Require Ed25519 keys, clean out conflicting
50-cloud-init.confoverrides, and confirmsshd -Treportspasswordauthentication noandpermitrootlogin no. - Restrict port
22to VPN/bastion CIDRs inUFW, backed by Fail2Ban[sshd]and[recidive]jails. - Add
5mto15mfor:hold windows on utilization metrics so brief cron spikes never page humans. - Use Alertmanager
inhibit_rulesto suppress child service alerts wheneverHostDownor a higher-severity twin is active. - Delete or retune any alert rule that fires twice in a month without requiring human intervention.