Harden SSH Daemon to CIS Level 1 with sshd_config Drop-In
OpenSSH reads /etc/ssh/sshd_config and any file in /etc/ssh/sshd_config.d matching *.conf in lexical order, with later directives overriding earlier ones. A numbered drop-in such as 50-cis.conf is the cleanest way to enforce CIS 5.2.x without touching the vendor file, because distro upgrades may rewrite the base config. Internally, sshd parses each keyword, applies Match blocks contextually, and binds the effective policy to each incoming connection; running sshd -T dumps the fully resolved configuration for verification.
Production use cases include standardizing SSH posture across thousands of nodes via Ansible, enforcing MFA via AuthenticationMethods for admin roles, and disabling password auth on cloud instances where only key-based access is allowed. Compliance teams routinely scrape sshd -T output into their evidence pipeline because it reflects the running daemon rather than the on-disk file.
Security implications are direct: PermitRootLogin no, MaxAuthTries 4, and disabling weak KEX and ciphers materially reduce brute-force and downgrade risk. Performance impact is negligible. Common pitfalls include locking yourself out by testing on the only SSH session before reloading, forgetting to restart sshd versus reload, and using deprecated directives like UsePrivilegeSeparation that cause sshd -t to fail on modern versions. Always validate with sshd -t before systemctl reload sshd.
> System.Execute()
sudo tee /etc/ssh/sshd_config.d/50-cis.conf >/dev/null <<'EOF'
Protocol 2
PermitRootLogin no
MaxAuthTries 4
MaxSessions 10
PubkeyAuthentication yes
PasswordAuthentication no
PermitEmptyPasswords no
X11Forwarding no
AllowTcpForwarding no
ClientAliveInterval 300
ClientAliveCountMax 3
LogLevel VERBOSE
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group16-sha512
EOF
sudo sshd -t && sudo systemctl reload sshd
sudo sshd -T | grep -E 'permitrootlogin|maxauthtries|passwordauthentication'
> Architecture & Security Context
Verified for Valters IT Hub. When deploying this configuration in a production homelab or enterprise environment, ensure that you monitor system resources and implement strict access controls. Administrator privileges are required.
ID: VALTERSIT-38AFEB6D607C