A read-only hardening auditor for Linux and macOS. One command checks 76 security settings, gives you a score and a prioritized "fix first" list, writes a clean HTML report, and tells you what changed since last time. Pure Python, no dependencies, and it never modifies your system.
python3 -m hostguard # audit this machine
python3 -m hostguard audit --format html -o report.htmlhostguard 1.1.0 linux (root: /)
Score: 34/100 grade F | 12 passed, 25 failed, 5 warnings, 23 skipped
Categories
SSH 62% 7 pass, 6 fail, 1 warn
Accounts 30% 2 pass, 5 fail, 1 warn
Files 30% 2 pass, 5 fail, 0 warn
Network 18% 1 pass, 4 fail, 0 warn
Kernel 0% 0 pass, 3 fail, 0 warn
Fix first (25)
[HIGH ] HG-ACC-001 Only root has UID 0
found: extra UID 0 accounts: toor
fix: Remove or renumber the extra UID 0 accounts listed in /etc/passwd.
[HIGH ] HG-SSH-001 SSH root login is not allowed with a password
found: PermitRootLogin yes
fix: Set 'PermitRootLogin no' (or 'prohibit-password') in /etc/ssh/sshd_config and reload sshd.
...
The example above (and docs/sample-report.html, the same data as an HTML report) comes from a deliberately
weak, entirely fake filesystem generated by examples/make_sample_report.py. Download the file and open it in a browser.
- Read-only by design. It reads files and runs a short allow-list of inspection tools (
sysctl,defaults,fdesetup,csrutil,spctl,lsof,ss,uname, the macOS firewall query). Anything else is refused in code, and--no-commandsturns external tools off entirely. - Understandable output. Every finding says what it found, why it matters, and how to fix it.
hostguard explain HG-SSH-001prints the details. - Drift detection.
hostguard diff old.json new.jsonshows new failures and fixed checks, and exits1on regressions, so you can run it from cron or CI. - Audit offline.
--root DIRaudits an extracted filesystem or container image without running it. Symlinks are re-rooted, so a hostile image cannot make the audit read files from your host. - No install friction. Standard library only. Works from a checkout, or with
pip install ..
git clone https://github.com/TPOALOS/hostguard && cd hostguard
python3 -m hostguard --version # run from the checkout, nothing to install
pip install . # optional: installs the `hostguard` command
hostguard auditPython 3.9+. CI runs 3.9, 3.12, 3.14 and 3.15 on Ubuntu, and 3.9 on macOS every week. Not published on PyPI.
hostguard # same as `hostguard audit`
sudo hostguard audit # as root it can also read /etc/shadow and /etc/sudoers (still read-only)
hostguard audit --format html -o report.html
hostguard audit --format json -o today.json
hostguard audit --category ssh --min-severity MEDIUM
hostguard audit --only HG-SSH-001 --only HG-FIL-009
hostguard audit --skip HG-NET-008 # e.g. this host is a router on purpose
hostguard audit --no-commands # files only, no external tools
hostguard list --platform darwin # all checks
hostguard explain HG-KRN-004 # why a check exists and how to fix it
hostguard diff last-month.json today.json # what got better or worse| Option | Meaning |
|---|---|
--format text|json|html|md, -o FILE |
report format and destination |
--fail-under SCORE |
exit 1 when the score is below SCORE |
--fail-on high|medium|low |
exit 1 when a check of that severity or higher fails |
--root DIR, --platform linux|darwin |
audit an extracted filesystem (platform defaults to linux) |
--ignore-ownership |
skip file-owner checks, for trees extracted as a normal user |
--include-hostname |
add the hostname to the report (omitted by default) |
Exit codes: 0 ok, 1 a threshold was breached (or diff found regressions), 2 usage error.
- name: Hardening audit of the runner image
run: python -m hostguard audit --fail-on high --no-commandsdocker create --name tmp myimage && docker export tmp | tar -x -C ./rootfs && docker rm tmp
hostguard audit --root ./rootfs --ignore-ownership --format html -o image-report.html76 checks in 9 categories; the full list with severities is in docs/CHECKS.md.
| Category | Examples |
|---|---|
| SSH (15) | root login, password authentication, empty passwords, weak ciphers/MACs, grace time, sshd_config and host key permissions |
| Accounts (9) | extra UID 0 accounts, empty passwords, system-account shells, password aging, NOPASSWD sudo rules, .rhosts |
| Files (12) | /etc/passwd, shadow, sudoers permissions, world-writable files in /etc, sticky /tmp, unsafe PATH, private SSH keys |
| Network (11) | redirects, source routing, SYN cookies, risky services listening (telnet, Redis, Docker API, databases, SMB...), host firewall |
| Kernel (10) | ASLR, kptr_restrict, ptrace_scope, link protections, mitigations=off on the boot command line |
| Services (3) | legacy services (telnet, rsh, tftp), unneeded services, inetd/xinetd |
| Updates (1), Logging (4) | automatic security updates, time sync, persistent logs, auditd, core dumps |
| macOS (11) | FileVault, SIP, Gatekeeper, application firewall and stealth mode, automatic updates, guest account, auto-login, screen lock |
Scoring: each assessed check counts by severity (HIGH 5, MEDIUM 3, LOW 1); a pass earns the full weight, a warning half, a failure nothing. Skipped checks (not installed, not applicable, needs root) are excluded, so the score only reflects what could be assessed. The grade is A 90+, B 80+, C 70+, D 60+, otherwise F.
- hostguard is a practical guide, not a compliance tool. It is not CIS-certified and does not claim to implement any benchmark; the checks are written from common hardening guidance. For formal compliance use a dedicated product.
- A high score does not mean a machine is secure; it means these settings look sensible. Some checks are judgement calls (for example, a router should have IP forwarding on).
- It inspects configuration files and a few system settings. It does not scan for malware, check package versions against vulnerability databases, or test the network.
- Coverage is partial without root (it skips what it cannot read and says so). Linux checks assume common layouts (systemd, Debian/Red Hat families); other setups are skipped or reported as warnings.
- Linux behaviour is verified by tests against fake filesystems and by CI on Ubuntu; it was developed on macOS and has not been run on a wide range of real distributions.
- Reports contain paths, user names and settings from the machine. Hostnames are left out by default; review a report before sharing it.
from hostguard.model import check, fail, ok
@check("HG-SSH-016", "SSH uses a banner", "SSH", "LOW",
why="Legal banners support prosecution and deter casual misuse.",
fix="Set 'Banner /etc/issue.net' in sshd_config.")
def _banner(env):
text = env.read_text("/etc/ssh/sshd_config") or ""
return ok("banner set") if "Banner " in text else fail("no Banner directive")Checks use env.read_text, env.stat, env.listdir, env.walk and env.run (allow-listed). Tests build a fake root directory
(see tests/util.py), so no check needs a real system. Regenerate the reference with python3 scripts/gen_checks_doc.py.
hostguard/env.py read-only access to a root (symlink-safe) and the allow-listed command runner
hostguard/model.py statuses, severities, check registry
hostguard/checks/ the checks, one module per area
hostguard/engine.py runs checks; a broken check never stops the audit
hostguard/scoring.py weighted score and grade
hostguard/report.py text, JSON, Markdown and HTML (no JavaScript, everything escaped)
hostguard/diff.py report comparison
hostguard/cli.py command line
python3 -m unittest -vEvery check has passing and failing fixtures, plus path-escape and allow-list tests for the environment, scoring and report tests (including HTML escaping), the CLI, and consistency checks that keep version numbers, the check reference and the CI workflow honest.
MIT (c) TPOALOS
More tools by TPOALOS: detectlite · backtestlint · riskmetrics · edgelab · toolbox