Skip to content

SSH Bastion Hardening & Fail2ban with Systemd Backend

SOP-SEC-004 Standard Operating Procedure v2.0.0
Last Updated 2026-10-14
Author Systems Administration & SecOps Team
πŸ’» Target OS / Systems:
Ubuntu 24.04 / 26.04 LTSDebian 12 / 13OpenSSH Serversystemd-journald / Fail2ban

Before you begin

  • Applies to:Linux SSH bastion hardening with Fail2ban and a systemd journal backend.
  • Where to start:Start with a console or an approved fallback connection to the bastion. Test access separately before closing the original session.
  • What you need:Have administrator access, approved management sources, a tested SSH login, and backups of the existing configuration.
Guide tools
Guide tools
0/0 Steps (0%)

Scope, Purpose & Architecture Baseline

This procedure establishes a baseline for hardening public-facing or perimeter SSH bastion hosts and configuring Fail2ban to mitigate brute-force attempts.

AttributeSpecification
Document IDSOP-SEC-004 (Revision 2)
ClassificationOperational Guide
Subsystemsystemd-journald, sshd, fail2ban
Change Window Required?Yes (brief SSH service reload)
SSH Bastion Host Architecture with Systemd Journald and Fail2ban Defense Diagram

Hardened SSH Bastion Architecture: Public SSH access restricted to Ed25519 cryptographic keys on non-standard ports, actively monitored by Fail2ban via the systemd-journald backend to dynamically inject kernel firewall bans (nftables/iptables) against brute-force attacks.


Phase 1: Pre-Flight & Key Provisioning

01

Generate and Deploy Ed25519 Public Key

Key Management

Generate an Ed25519 keypair with 100 key-derivation function (KDF) rounds on the local administrative workstation and copy the public key to the bastion host.

Terminal window
# 1. Generate key with 100 KDF rounds (run on local workstation)
ssh-keygen -t ed25519 -a 100 -C "admin-bastion-2026"
# 2. Transfer public key to target bastion server
ssh-copy-id -i ~/.ssh/id_ed25519.pub sysadmin@<BASTION_IP>
# 3. Confirm keypair authentication succeeds before hardening daemon
ssh -i ~/.ssh/id_ed25519 sysadmin@<BASTION_IP>

Phase 2: OpenSSH Daemon Hardening

02

Deploy Modular Hardened Directives via Drop-In

OpenSSH Configuration

Avoid editing /etc/ssh/sshd_config directly. Deploy a modular drop-in file under /etc/ssh/sshd_config.d/, disable root login and passwords, and validate syntax before restarting.

Terminal window
# Create drop-in configuration file
sudo tee /etc/ssh/sshd_config.d/99-hardened-ssh.conf > /dev/null << 'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
MaxSessions 4
ClientAliveInterval 300
ClientAliveCountMax 2
EOF
# Pre-Restart Syntax Test: Verify configuration syntax
sudo sshd -t
# Apply new configuration if no errors are reported
sudo systemctl restart ssh

Phase 3: Fail2ban with Journald Backend

03

Install & Configure Fail2ban for Systemd Integration

Intrusion Prevention

Install Fail2ban and Python systemd bindings, then configure a dedicated jail override utilizing the systemd backend with strict rate limits.

Terminal window
# Install Fail2ban along with systemd Python bindings
sudo apt update && sudo apt install -y fail2ban python3-systemd
# Create modular jail override
sudo tee /etc/fail2ban/jail.d/sshd-systemd.local > /dev/null << 'EOF'
[sshd]
enabled = true
port = ssh
mode = aggressive
backend = systemd
maxretry = 3
findtime = 600
bantime = 3600
ignoreip = 127.0.0.1/8 ::1 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16
EOF
# Enable and start Fail2ban service
sudo systemctl enable --now fail2ban

Phase 4: Operational Verification & Ingestion Test

04

Verify Fail2ban Ingestion and Live Systemd Journal Matching

Verification

Verify that the Fail2ban SSH jail is actively inspecting the systemd journal and tracking authentication failures.

Terminal window
# Inspect active jail status
sudo fail2ban-client status sshd
# Expected Output Verification:
# Status for the jail: sshd
# |- Filter
# | |- Currently failed: 0
# | |- Total failed: 0
# | `- Journal matches: _SYSTEMD_UNIT=ssh.service + _COMM=sshd
# `- Actions
# |- Currently banned: 0
# |- Total banned: 0
# `- Banned IP list:

Phase 5: Emergency Operations & Rollback

05

Emergency Unban and Service Rollback

Incident Response

Unban accidentally blocked administrative IPs or execute complete rollback to default configuration if connectivity anomalies occur.

Terminal window
# Option A: Emergency Unban of Administrator IP Address
sudo fail2ban-client set sshd unbanip <BLOCKED_IP>
# Option B: Complete Rollback of Hardening Overrides
sudo rm -f /etc/ssh/sshd_config.d/99-hardened-ssh.conf /etc/fail2ban/jail.d/sshd-systemd.local
sudo systemctl restart ssh && sudo systemctl restart fail2ban
# Confirm listening status
systemctl is-active ssh

Comments