Audit sshd_config, sshd -T or a live SSH server's offered algorithms against CIS/NIST SSH hardening guidance (MIT, free; pipx install) https://errant.solutions/tools/sshd-hardening-auditor.html
  • Python 88.4%
  • Shell 9.8%
  • HTML 1.8%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
CanuteTheGreat c5aeacefea
All checks were successful
tests / audit (push) Successful in 34s
tests / test (3.14) (push) Successful in 1m0s
tests / test (3.8) (push) Successful in 59s
tests: kill ssh_kexinit mutmut_32 (banner scan must split on the first newline when junk line, banner and packet arrive in one read); mutation floor unchanged
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-30 17:46:22 -08:00
.forgejo/workflows Shared CLI contract: exit codes, --json schema_version, --quiet 2026-11-23 14:35:15 -08:00
ci tests: kill the 2.0.0 mutation survivors (whole --help body incl. raw docstring, _main defaults/call args/json layout, every field of audit_files and get_live_config); full run on rw-man-01: 84.06% -> 92.68%, 246 -> 107 survivors; raise mutation floor 83 -> 92. Remaining survivors are equivalent (profile default None/'L2'/'XXl2XX' behave as l2, fail-on 'HIGH' is upper()-cased, banner '' vs None, _seconds, split maxsplit) 2026-11-24 13:05:51 -08:00
docs Shared CLI contract: exit codes, --json schema_version, --quiet 2026-11-23 14:35:15 -08:00
keys release: sign SHA256SUMS with the Errant Solutions release key 2026-11-17 10:27:11 -08:00
schema Shared CLI contract: exit codes, --json schema_version, --quiet 2026-11-23 14:35:15 -08:00
tests tests: kill ssh_kexinit mutmut_32 (banner scan must split on the first newline when junk line, banner and packet arrive in one read); mutation floor unchanged 2026-11-30 17:46:22 -08:00
.gitignore nightly mutation: incremental (only functions changed since the last green run) except a weekly full run on the repo's own weekday; replace-queued concurrency; staggered cron 2026-10-18 12:22:55 -07:00
CHANGELOG.md Shared CLI contract: exit codes, --json schema_version, --quiet 2026-11-23 14:35:15 -08:00
claims.json Shared CLI contract: exit codes, --json schema_version, --quiet 2026-11-23 14:35:15 -08:00
LICENSE Initial commit: SSH hardening auditor v1 2026-09-13 21:29:58 -07:00
pyproject.toml docs: security contact moves to security@support.errant.solutions (author email in package metadata too); signing-key UID text unchanged 2026-11-30 10:29:58 -08:00
README.md Shared CLI contract: exit codes, --json schema_version, --quiet 2026-11-23 14:35:15 -08:00
report.html Initial commit: SSH hardening auditor v1 2026-09-13 21:29:58 -07:00
SECURITY.md docs: security contact moves to security@support.errant.solutions (author email in package metadata too); signing-key UID text unchanged 2026-11-30 10:29:58 -08:00
sshd_audit.py Shared CLI contract: exit codes, --json schema_version, --quiet 2026-11-23 14:35:15 -08:00

SSH Hardening Auditor

A single-file, dependency-free Python script that audits an sshd_config (or a live server's effective config via sshd -T) against CIS Benchmark / NIST-aligned SSH hardening recommendations — catches weak ciphers/KEX/MACs, password auth left enabled, root login, empty passwords, and more.

By Errant Solutions (errant.solutions), makers of Rustinion (device provisioning & monitoring), /Dev/Out Digital (security awareness training), OOPS! (hands-on security labs), and SSHerpa (Android SSH client).

Why

Every "harden your SSH server" checklist online is a blog post you have to manually diff against your config by eye. This is a real, runnable, testable tool instead — one Python file, stdlib only, works on any box with Python 3.8+.

Install

pipx install git+https://git.canutethegreat.com/CanuteTheGreat/sshd-hardening-auditor.git        # latest release branch; puts `sshd-hardening-auditor` on PATH
pipx install git+https://git.canutethegreat.com/CanuteTheGreat/sshd-hardening-auditor.git@v2.0.0  # a pinned release
brew install canutethegreat/errant-tools/sshd-hardening-auditor   # after: brew tap canutethegreat/errant-tools https://git.canutethegreat.com/CanuteTheGreat/homebrew-errant-tools
scoop install errant-tools/sshd-hardening-auditor                 # after: scoop bucket add errant-tools https://git.canutethegreat.com/CanuteTheGreat/scoop-errant-tools

Or download the single file (stdlib-only Python 3.8+) and run it directly: curl -fsSLO https://errant.solutions/downloads/sshd_audit.py && python3 sshd_audit.py --help. Every release has a changelog, the wheel, the sdist and a SHA256SUMS file. The checksums are signed (SHA256SUMS.asc). Verify: gpg --verify SHA256SUMS.asc SHA256SUMS (key: https://errant.solutions/signing-key.asc, fingerprint 5439 3549 39B9 C055 2A68 E9BB E323 A6A3 AC0A 6506, also in keys/release-signing.asc). Not on PyPI yet, so plain pipx install sshd-hardening-auditor doesn't work until it's published there.

Usage

sshd-hardening-auditor /etc/ssh/sshd_config      # a config file (the default path)
sudo sshd-hardening-auditor --live               # the effective config from `sshd -T`
sshd-hardening-auditor --remote host.example.com # what a running server offers on the wire (port 22)
sshd-hardening-auditor --remote 10.0.0.5:2222 --json
sshd-hardening-auditor --fail-on medium sshd_config   # CI gate: exit 1 on MEDIUM or worse
sshd-hardening-auditor --html report.html sshd_config
sshd-hardening-auditor --profile l1 sshd_config       # CIS Level 1 rules only
sshd-hardening-auditor --fix fix.conf sshd_config     # write a drop-in that fixes the findings

--remote connects, exchanges SSH identification strings and reads the server's KEXINIT (the algorithm lists it offers). It never logs in or sends credentials, so it works on any server you're allowed to connect to, including appliances where you can't run sshd -T.

--profile l1|l2 picks the CIS profile. l2 (the default) runs every rule; l1 leaves out the three that CIS files under Level 2: X11Forwarding, AllowTcpForwarding and GSSAPIAuthentication (the benchmarks differ a little between distributions; this follows the common Linux ones). Algorithm, host key and file permission checks are in both profiles.

--fix FILE writes an sshd_config drop-in (- = stdout) that sets every failing directive to the recommended value. It never edits your config: review it, put it where its Include line comes before the conflicting directives (sshd keeps the first value), run sshd -t, keep a second session open, then reload. AllowUsers/AllowGroups and weak algorithms need your decision, so they come out as comments.

What it checks

  • Authentication: PermitRootLogin, PasswordAuthentication, PermitEmptyPasswords, HostbasedAuthentication, Protocol (HIGH); KbdInteractiveAuthentication (ChallengeResponseAuthentication), StrictModes, X11Forwarding, MaxAuthTries, PermitUserEnvironment, IgnoreRhosts (MEDIUM); GSSAPIAuthentication, UsePAM, AllowUsers/AllowGroups/DenyUsers/DenyGroups (LOW)
  • CIS session limits and logging: LogLevel (INFO/VERBOSE), MaxSessions, MaxStartups (10:30:60 or stricter), Banner, ClientAliveInterval, ClientAliveCountMax, LoginGraceTime, AllowTcpForwarding (LOW)
  • Algorithms (configured lists, sshd -T output, or what --remote sees offered):
    • key exchange: SHA-1 and 1024-bit DH groups (HIGH), NIST ecdh-sha2-nistp* (LOW), and whether a hybrid post-quantum KEX (sntrup761x25519, mlkem768x25519) is offered (LOW)
    • host keys: ssh-dss (HIGH), SHA-1 ssh-rsa (MEDIUM), ecdsa-sha2-nistp* (LOW)
    • ciphers: every CBC mode, arcfour, 3DES, blowfish, cast128, none (HIGH)
    • MACs: MD5 and truncated SHA-1 (HIGH), hmac-sha1, umac-64 (MEDIUM), non-ETM (encrypt-and-MAC) variants (LOW)
  • Terrapin (CVE-2023-48795, --remote): chacha20-poly1305 or CBC+EtM offered without strict key exchange (MEDIUM); pre-authentication zlib compression (LOW)
  • Files (CIS 5.2.1-5.2.3): sshd_config and host private keys owned by root and mode 0600; RSA host keys under 2048 bits (HIGH) or under 3072 (LOW), DSA host keys (HIGH). --no-file-checks skips these.

The config is read the way sshd itself reads it: Include drop-ins (e.g. /etc/ssh/sshd_config.d/*.conf) are expanded in place, the first value of a directive wins, settings inside Match blocks don't override the global ones, and an unset directive is judged on OpenSSH's built-in default (shown as <value> (default)). Times use sshd's format (90, 1m30s, 2h), and LoginGraceTime 0 / ClientAliveCountMax 0 (which switch the limit off) fail their rules. One version difference: OpenSSH before 10.1 keeps the last of several MaxStartups lines; --live always shows what your sshd really uses. An algorithm list written with +/-/^ is relative to OpenSSH's defaults, so only the named algorithms are judged; use --live or --remote to judge the full effective list. The test suite cross-checks file mode against the real sshd -T (including 200 random configs in tests/test_accuracy.py), and --remote against a real running sshd, on every CI run.

Exit codes (same convention as every Errant Solutions tool):

Code Meaning
0 no failed check at or above --fail-on (default high)
1 at least one failed check at or above --fail-on
2 usage or input error: bad arguments, the config couldn't be read, sshd -T couldn't run, or the remote server couldn't be reached (legacy: these cases were always 2 and stay 2)
3 an unexpected internal error (message on stderr, never a traceback)

Each finding includes the current value, the expected value, and a one-line rationale — so it doubles as a mini security-training doc for whoever reads the output.

Exit codes and JSON output

The tool follows the shared Errant Solutions CLI contract (docs/CLI-CONTRACT.md). --json prints exactly one object: schema_version (1), tool, version, exit_code and results (the list of checks, each with key, value, expected, severity, pass, rationale). The JSON Schema is schema/sshd-hardening-auditor.schema.json. --quiet / -q prints nothing to stdout (no report, no JSON, no --fix - snippet); the exit code, errors on stderr and files from --html and --fix FILE remain. Errors always go to stderr.

Example: sshd-hardening-auditor --json --no-file-checks sshd_config prints {"schema_version": 1, "tool": "sshd-hardening-auditor", "version": "2.0.0", "exit_code": 1, "results": [...]}.

CI integration example

# .forgejo/workflows/ssh-audit.yml (or any CI)
- name: Audit sshd_config
  run: pipx run --spec git+https://git.canutethegreat.com/CanuteTheGreat/sshd-hardening-auditor.git sshd-hardening-auditor --no-file-checks deploy/sshd_config

License

MIT — see LICENSE. Free to use, modify, and redistribute. If it saves you time, pay what you think it's worth here — or check out Rustinion for full fleet-wide config compliance monitoring.

Roadmap ideas (not yet built)

  • Compare against a specific CIS Benchmark level (1 vs 2) profile flag
  • --fix mode that writes a hardened config with an explained diff

Tests

tests/ runs every option and check end-to-end (including --live and --remote against a real OpenSSH server) on Python 3.8 and current Python in Forgejo CI: sh ci/run-tests.sh 3.13 reproduces it locally (needs docker).