Infrastructure Notes

Infrastructure Notes: Tightening SSH Baselines and Alert Noise

By Nikhil Bhangale··6 min read

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.

Infrastructure Notes: Tightening SSH Baselines and Alert Noise

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:

bash · terminal
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:

output / text
# /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:

bash · terminal
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:

bash · terminal
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:

config / ini
[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 LabelDelivery ChannelMinimum for: DurationExample Trigger ConditionExpected Operator Action
criticalPagerDuty / Phone Wakeup2m to 5mHost unreachable, HTTP 5xx above 2%, FPM socket dead, disk above 92%Acknowledge and remediate immediately
warningDedicated Slack #ops-warn10m to 15mDisk projected full in 48h, worker pool above 80%, elevated CPU stealInvestigate during current workday
infoDaily digest / Ticket queue30m to 1hTLS certificate under 21 days, kernel reboot pendingSchedule in weekly maintenance sprint

Finally, we added inhibit_rules inside /etc/prometheus/alertmanager.yml so root-cause outages automatically mute downstream symptom alerts:

yaml
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

  1. Require Ed25519 keys, clean out conflicting 50-cloud-init.conf overrides, and confirm sshd -T reports passwordauthentication no and permitrootlogin no.
  2. Restrict port 22 to VPN/bastion CIDRs in UFW, backed by Fail2Ban [sshd] and [recidive] jails.
  3. Add 5m to 15m for: hold windows on utilization metrics so brief cron spikes never page humans.
  4. Use Alertmanager inhibit_rules to suppress child service alerts whenever HostDown or a higher-severity twin is active.
  5. Delete or retune any alert rule that fires twice in a month without requiring human intervention.
#ssh#security#ufw#fail2ban#linux
← Back to all posts

Related Articles

Browse all articles →
Infrastructure Notes12 min read

Moving to a CDN Without Overwhelming Your Origin (or Blocking Googlebot)

Learn how to migrate to a CDN like Cloudflare without triggering cache-miss storms on your Linux origin, breaking real visitor IPs, or accidentally blocking Googlebot.

Read article →
Infrastructure Notes11 min read

Microsoft Outlook Outage November 2026: What Broke, Who Was Hit, and How to Respond

How the November 2026 Exchange Online cascading server failure appeared on downstream Linux mail relays, with hands-on Postfix transport throttling, cPanel Exim triage, swaks diagnostics, and DKIM queue safety.

Read article →
Infrastructure Notes7 min read

How to Handle a SYN Attack on a Hosting Server Without Taking Down the Customer Website

When a SYN flood hits one customer IP, null routing stops the attack but also takes the site offline. Here's a practical hosting workflow: confirm the attack, protect first, migrate when needed, and only blackhole as a last resort.

Read article →
Chat on WhatsApp