OpenSSH remains the dominant remote administration protocol on Debian servers (Debian 12 bookworm and Debian 13 trixie in 2026), but its default configuration still contains several legacy concessions that significantly increase risk in production environments. Hardening SSH is primarily about removing entire classes of attack vectors rather than adding incremental mitigations.
The most impactful improvements come from eliminating three major weaknesses that appear in virtually every real-world compromise involving SSH:
- Credential-based authentication (passwords, keyboard-interactive)
- Direct root login over the network
- Support for cryptographically weak or deprecated key exchange, host key, cipher, and MAC algorithms
Core Threat Model & Mitigation Rationale (2026 Perspective)
Modern attackers rarely attempt sophisticated exploits against OpenSSH itself (memory-safety bugs are now extremely rare thanks to years of hardening and memory-safe rewrites in critical paths). Instead, the overwhelming majority of successful intrusions follow one of these patterns:
- Automated brute-force or credential stuffing against password-authenticated accounts
- Credential theft from compromised workstations → reused passwords or stolen private keys
- Exploitation of weak legacy algorithms during key exchange or host authentication (Logjam, Terrapin prefix truncation, older RSA/DH groups)
- Persistence via authorized_keys injection after initial foothold
- Lateral movement via root-equivalent access obtained directly over SSH
Effective hardening therefore prioritizes:
- Cryptographic elimination of password and weak-algorithm paths
- Privilege boundary enforcement (no direct root)
- Tight control over allowed identities and source networks
- Behavioral rate-limiting and anomaly detection at the network and application layer
Recommended Production Configuration Profile
The configuration below reflects current cryptographic best practices (2025–2026), Debian packaging realities, and operational experience from internet-facing and internal bastion hosts.
Key directives and their justification:
- PasswordAuthentication no Removes the entire password-authentication code path from the attack surface. Forces all authentication to cryptographic public-key material, which cannot be brute-forced at scale.
- PermitRootLogin no (or prohibit-password if emergency console access is required) Enforces the principle of least privilege at authentication time. Even if an attacker obtains a valid key for an ordinary user, they must perform an additional privilege escalation step (sudo), which can be audited, rate-limited, and protected with MFA.
- PubkeyAuthentication yes + AuthenticationMethods publickey Explicitly enforces single-factor public-key authentication. Prevents accidental fallback to less secure methods.
- HostKey restricted to ed25519 and strong ECDSA curves only ed25519 provides the best security-per-bit ratio, constant-time implementation, and resistance to side-channel attacks. Removing RSA (especially <4096 bits) and DSA eliminates classes of factoring and small-subgroup attacks.
- PubkeyAcceptedKeyTypes limited to modern signatures Prevents acceptance of SHA-1 based RSA signatures or obsolete key formats.
- KexAlgorithms, Ciphers, MACs explicitly set (or verified) to post-Quantum-KEM-ready and Terrapin-resistant lists OpenSSH 9.6+ defaults already removed most weak options, but explicitly listing ensures no accidental inheritance of legacy system-wide crypto policies.
- MaxAuthTries 3, LoginGraceTime 30 Drastically reduces the speed of online password-guessing attacks (even if passwords were somehow still enabled).
- ClientAliveInterval 300 / ClientAliveCountMax 0 Quickly terminates abandoned or stalled connections, reducing resource consumption during slowloris-style probes.
- AllowUsers or AllowGroups with source IP/net restrictions The single most powerful control after eliminating passwords. Restricting both identity and network origin implements network-segment-aware least privilege.
Additional Defense-in-Depth Layers
- fail2ban or equivalent log-based IPS Even with passwords disabled, fail2ban still catches malformed protocol attempts, key mismatches, and repeated connection storms.
- Firewall-level source restrictions (UFW/nftables) Allow SSH only from management networks, bastion hosts, or VPN exit points. This blocks the vast majority of Internet background noise.
- ed25519 keys exclusively Generate all new keys with ssh-keygen -t ed25519. Rotate out any remaining RSA/DSA/ECDSA keys.
- Authorized_keys file permissions & ownership 700 for ~/.ssh, 600 for authorized_keys. Enforce via PAM or filesystem ACLs if shared-home-directory environments exist.
- SSH certificates instead of static keys (advanced) Short-lived certificates signed by an internal CA allow centralized key rotation, validity periods, forced commands, and revocation — dramatically reducing key management risk.
- Logging & alerting Monitor for unusual patterns: new keys added, logins from unexpected networks, high failure rates even when passwords are disabled (indicates key-guessing or misconfiguration attempts).
Verification & Testing Discipline
After changes:
- Always test configuration syntax first (sshd -t)
- Verify applied settings (sshd -T | grep -iE ‘password|permitroot|pubkey|kex|cipher|mac|allowusers’)
- Attempt login from an untrusted network before closing the current session
- Confirm key-based login works before logging out of the last working shell
This profile renders automated SSH compromise economically infeasible for the vast majority of adversaries while imposing only moderate operational overhead.