Linux Benchmark & Compliance Scanning
Distro support
Two-family skill. OpenSCAP (oscap) and Lynis run on both families;
the difference is which SCAP Security Guide (SSG) datastream you point
oscap at — there is one per distro and major version. On the RHEL family
SSG is first-class (scap-security-guide, openscap-scanner); on
Debian/Ubuntu the packages exist but profile coverage is thinner, so Lynis
often does more of the work. Body uses the RHEL family for OpenSCAP (where
coverage is strongest) and is family-neutral for Lynis. Substitute per this
matrix.
| Concept |
Debian/Ubuntu |
RHEL family |
| OpenSCAP scanner |
apt install openscap-scanner ssg-debderived |
dnf install openscap-scanner scap-security-guide |
| SSG datastream dir |
/usr/share/xml/scap/ssg/content/ |
/usr/share/xml/scap/ssg/content/ |
| Datastream file |
ssg-ubuntu2204-ds.xml (version-specific) |
ssg-rhel9-ds.xml (version-specific) |
| List profiles |
oscap info <ds.xml> |
oscap info <ds.xml> (same) |
| Lynis |
apt install lynis |
dnf install lynis (EPEL on RHEL/Rocky/Alma) |
| Lynis run |
lynis audit system |
lynis audit system (same) |
OpenSCAP gives you policy compliance against a formal benchmark (CIS,
STIG, PCI-DSS) with pass/fail per rule and auto-generated remediation. Lynis
gives you a fast, opinion-rich hardening sweep with a numeric index and
prioritized suggestions — no formal benchmark, but excellent at surfacing
operational weaknesses (file perms, kernel params, missing tooling). Run
both: OpenSCAP for the audit trail, Lynis for the quick wins. They complement
the other two compliance layers — linux-auditd-rules (attribution) and
linux-file-integrity (drift). See
../../docs/multi-distro/plan.md.
Use When
- Running a CIS / STIG / PCI-DSS scan with OpenSCAP and producing a report.
- Generating a remediation script or Ansible playbook from a scan.
- Running a quick Lynis hardening sweep to get a score and suggestions.
- Choosing the correct SSG datastream and profile for a host.
Do Not Use When
- The task is defining or analysing audit rules; use
linux-auditd-rules.
- The task is file-content drift detection; use
linux-file-integrity.
- The task is applying hardening by hand (sysctl, SSH, SELinux); use
linux-server-hardening.
Required Inputs
| Artefact |
Source |
Required? |
If absent |
| Exact distro/version, role, scope, and benchmark/profile requirement |
Inventory and control owner |
yes |
Stop profile selection; do not scan against a guessed datastream. |
| Scanner/content versions, profile ID, tailoring, and exceptions |
Read-only package/content inspection |
yes |
Report coverage unavailable or run Lynis as a qualified secondary check. |
| Remediation authority, test host, rollback, and service constraints |
Change record |
remediation only |
Generate a draft only; do not apply. |
Capability Contract
Default to read-only: read/search installed content and run scans that do not remediate. Package installation, generated-script execution, Ansible application, service changes, and any --remediate action require explicit authority and a test host. A report is not certification.
Degraded Mode
If matching SCAP content/profile is unavailable, do not substitute a different distro/version. Return a coverage gap and optionally a read-only Lynis result. Unassessed rules remain unassessed, never passed; generated remediation remains an unexecuted draft.
Decision Rules
| Choice |
Action |
Failure or risk avoided |
| OpenSCAP or Lynis |
Use OpenSCAP for named policy evidence; Lynis for advisory hardening breadth. |
Treating an advisory score as compliance. |
| Datastream/profile |
Match exact distro major version and list profile IDs before evaluation. |
Invalid or misleading results. |
| Tailoring/exception |
Record business justification and expiry without rewriting raw results. |
Hidden control waiver. |
| Remediation |
Review generated changes, test with rollback, then rescan before production proposal. |
Breaking services or claiming unverified compliance. |
Workflow
- Read/search the exact host identity, installed scanner/content, datastream, profiles, tailoring, and prior exceptions; stop on a distro/profile mismatch.
- Record scope and run OpenSCAP in read-only evaluation mode, preserving XML plus human report and command metadata.
- Classify pass, fail, error, not applicable, and not checked separately; block any compliance claim with unresolved errors or coverage gaps.
- Optionally run read-only Lynis as a secondary advisory source and keep its findings distinct.
- Generate remediation only when requested; review each proposed change against services, ownership, and rollback.
- With separate authority, test remediation outside production and rescan the identical profile. Recover by reverting the test change and preserving pre/post evidence when a service or control regresses.
Quality standards
- Always match the SSG datastream to the exact distro and version.
- Treat OpenSCAP remediation as a draft — review every change before applying to production.
- Re-scan after remediation; a score only counts if it's reproduced.
- Capture
results.xml for the audit trail, not just the HTML report.
Anti-Patterns
- Applying
--remediate to production. Fix: generate, review, test, rollback-test, and rescan before proposing production change.
- Scanning with a mismatched datastream. Fix: verify distro major version, content package, and profile ID first.
- Chasing the Lynis index. Fix: prioritise named findings and risk, not the aggregate score.
- Calling a passing profile "secure". Fix: state benchmark scope, exceptions, errors, and out-of-scope threats.
- Counting errors/not-checked as passes. Fix: preserve result status and block unsupported compliance claims.
- Claiming certification from a local scan. Fix: describe assessment evidence only and defer certification to authorised assessors.
Outputs
| Artefact |
Consumer |
Acceptance condition |
| Scan evidence set |
Control owner |
Exact content/profile/tailoring, command, XML, human report, timestamp, and host identity are preserved. |
| Qualified findings summary |
System owner |
Separates pass/fail/error/not-checked/exceptions, prioritises failures, and states coverage limits. |
| Remediation draft/rescan |
Change owner |
Every change is reviewed/tested with rollback and identical-profile rescan, or remains clearly unexecuted. |
Evidence Produced
| Artefact |
Acceptance |
| Compliance scan pack |
Contains scanner/content versions, datastream/profile, raw XML, report, status counts, exceptions, errors, Lynis separation, and pre/post evidence where authorised. |
Worked Example
On RHEL 9, confirm ssg-rhel9-ds.xml, list the exact profile, run a read-only evaluation, preserve XML and HTML, and report errors separately. Generate remediation only as a draft unless a test-host change is explicitly authorised.
References
This skill is self-contained. Every command below is standard oscap or
lynis on its family (see Distro support for the install and datastream
substitutions). The sk-* script in the Optional fast path section is a
convenience wrapper — never required.
OpenSCAP: install, list profiles, scan
# RHEL family
sudo dnf install openscap-scanner scap-security-guide
# Debian/Ubuntu
sudo apt install openscap-scanner ssg-debderived
# List the profiles in your distro's datastream (pick the right ds.xml!)
oscap info /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml
# Evaluate against a CIS profile, writing machine + human reports
sudo oscap xccdf eval \
--profile xccdf_org.ssgproject.content_profile_cis \
--results results.xml \
--report report.html \
/usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml
results.xml is the audit-trail artefact; report.html is the readable
pass/fail breakdown. STIG, PCI-DSS, and HIPAA profiles live in the same
datastream — list them with oscap info and swap the --profile ID.
OpenSCAP: generate remediation
# Bash remediation script from a completed scan
sudo oscap xccdf generate fix \
--profile xccdf_org.ssgproject.content_profile_cis \
--fix-type bash \
--output remediate.sh \
results.xml
# Ansible playbook instead
sudo oscap xccdf generate fix \
--profile xccdf_org.ssgproject.content_profile_cis \
--fix-type ansible \
--output remediate.yml \
results.xml
Review every generated change. Apply on a test host first, then re-scan
to confirm the score improved before touching production. Full datastream
selection, profile IDs, and remediation detail in
references/openscap-reference.md.
Lynis: quick hardening sweep
sudo apt install lynis # dnf install lynis (EPEL on RHEL/Rocky/Alma)
sudo lynis audit system # interactive: score + suggestions
sudo lynis audit system --quiet --logfile /var/log/lynis.log # for cron/CI
# Results: hardening index + warnings + suggestions
sudo grep -E 'Hardening index|Warning|Suggestion' /var/log/lynis-report.dat
The hardening index is a quick directional score, not a benchmark. Work the
prioritized suggestions, then re-run. Detail in
references/lynis-reference.md.
Optional fast path (when sk-* scripts are installed)
Running sudo install-skills-bin linux-benchmark-scanning installs:
| Task |
Fast-path script |
| Auto-pick the SSG datastream, run OpenSCAP + Lynis, summarise scores |
sudo sk-benchmark-scan --profile cis |
This is an optional read-only wrapper around oscap and lynis — it scans
and reports, it never remediates. The commands above are the source of truth.
Scripts
This skill installs the following scripts to /usr/local/bin/. To install:
sudo install-skills-bin linux-benchmark-scanning
| Script |
Source |
Core? |
Purpose |
| sk-benchmark-scan |
scripts/sk-benchmark-scan.sh |
yes |
Read-only compliance scan on both families: auto-detect the distro/version, locate the matching SSG datastream, run oscap xccdf eval against the chosen profile (CIS/STIG/PCI-DSS) into timestamped results.xml + report.html, optionally run lynis audit system, and print a pass/fail + hardening-index summary. Never remediates. |
1---2name: linux-benchmark-scanning3description: Use when running read-only OpenSCAP or Lynis scans, selecting distro-matched profiles, interpreting failures, or drafting remediation on Debian/Ubuntu or RHEL-family hosts. Use linux-auditd-rules for attribution and linux-file-integrity for AIDE drift.4license: MIT5---6# Linux Benchmark & Compliance Scanning78## Distro support910Two-family skill. **OpenSCAP** (`oscap`) and **Lynis** run on both families;11the difference is which **SCAP Security Guide (SSG) datastream** you point12`oscap` at — there is one per distro and major version. On the RHEL family13SSG is first-class (`scap-security-guide`, `openscap-scanner`); on14Debian/Ubuntu the packages exist but profile coverage is thinner, so Lynis15often does more of the work. Body uses the RHEL family for OpenSCAP (where16coverage is strongest) and is family-neutral for Lynis. Substitute per this17matrix.1819| Concept | Debian/Ubuntu | RHEL family |20|---|---|---|21| OpenSCAP scanner | `apt install openscap-scanner ssg-debderived` | `dnf install openscap-scanner scap-security-guide` |22| SSG datastream dir | `/usr/share/xml/scap/ssg/content/` | `/usr/share/xml/scap/ssg/content/` |23| Datastream file | `ssg-ubuntu2204-ds.xml` (version-specific) | `ssg-rhel9-ds.xml` (version-specific) |24| List profiles | `oscap info <ds.xml>` | `oscap info <ds.xml>` (same) |25| Lynis | `apt install lynis` | `dnf install lynis` (**EPEL** on RHEL/Rocky/Alma) |26| Lynis run | `lynis audit system` | `lynis audit system` (same) |2728OpenSCAP gives you **policy compliance** against a formal benchmark (CIS,29STIG, PCI-DSS) with pass/fail per rule and auto-generated remediation. Lynis30gives you a **fast, opinion-rich hardening sweep** with a numeric index and31prioritized suggestions — no formal benchmark, but excellent at surfacing32operational weaknesses (file perms, kernel params, missing tooling). Run33both: OpenSCAP for the audit trail, Lynis for the quick wins. They complement34the other two compliance layers — `linux-auditd-rules` (attribution) and35`linux-file-integrity` (drift). See36[`../../docs/multi-distro/plan.md`](../../docs/multi-distro/plan.md).3738<!-- dual-compat-start -->39## Use When4041- Running a CIS / STIG / PCI-DSS scan with OpenSCAP and producing a report.42- Generating a remediation script or Ansible playbook from a scan.43- Running a quick Lynis hardening sweep to get a score and suggestions.44- Choosing the correct SSG datastream and profile for a host.4546## Do Not Use When4748- The task is defining or analysing audit rules; use `linux-auditd-rules`.49- The task is file-content drift detection; use `linux-file-integrity`.50- The task is applying hardening by hand (sysctl, SSH, SELinux); use `linux-server-hardening`.5152## Required Inputs5354| Artefact | Source | Required? | If absent |55|---|---|---|---|56| Exact distro/version, role, scope, and benchmark/profile requirement | Inventory and control owner | yes | Stop profile selection; do not scan against a guessed datastream. |57| Scanner/content versions, profile ID, tailoring, and exceptions | Read-only package/content inspection | yes | Report coverage unavailable or run Lynis as a qualified secondary check. |58| Remediation authority, test host, rollback, and service constraints | Change record | remediation only | Generate a draft only; do not apply. |5960## Capability Contract6162Default to read-only: read/search installed content and run scans that do not remediate. Package installation, generated-script execution, Ansible application, service changes, and any `--remediate` action require explicit authority and a test host. A report is not certification.6364## Degraded Mode6566If matching SCAP content/profile is unavailable, do not substitute a different distro/version. Return a coverage gap and optionally a read-only Lynis result. Unassessed rules remain unassessed, never passed; generated remediation remains an unexecuted draft.6768## Decision Rules6970| Choice | Action | Failure or risk avoided |71|---|---|---|72| OpenSCAP or Lynis | Use OpenSCAP for named policy evidence; Lynis for advisory hardening breadth. | Treating an advisory score as compliance. |73| Datastream/profile | Match exact distro major version and list profile IDs before evaluation. | Invalid or misleading results. |74| Tailoring/exception | Record business justification and expiry without rewriting raw results. | Hidden control waiver. |75| Remediation | Review generated changes, test with rollback, then rescan before production proposal. | Breaking services or claiming unverified compliance. |7677## Workflow78791. Read/search the exact host identity, installed scanner/content, datastream, profiles, tailoring, and prior exceptions; stop on a distro/profile mismatch.802. Record scope and run OpenSCAP in read-only evaluation mode, preserving XML plus human report and command metadata.813. Classify pass, fail, error, not applicable, and not checked separately; block any compliance claim with unresolved errors or coverage gaps.824. Optionally run read-only Lynis as a secondary advisory source and keep its findings distinct.835. Generate remediation only when requested; review each proposed change against services, ownership, and rollback.846. With separate authority, test remediation outside production and rescan the identical profile. Recover by reverting the test change and preserving pre/post evidence when a service or control regresses.8586## Quality standards8788- Always match the SSG datastream to the exact distro and version.89- Treat OpenSCAP remediation as a draft — review every change before applying to production.90- Re-scan after remediation; a score only counts if it's reproduced.91- Capture `results.xml` for the audit trail, not just the HTML report.9293## Anti-Patterns9495- Applying `--remediate` to production. Fix: generate, review, test, rollback-test, and rescan before proposing production change.96- Scanning with a mismatched datastream. Fix: verify distro major version, content package, and profile ID first.97- Chasing the Lynis index. Fix: prioritise named findings and risk, not the aggregate score.98- Calling a passing profile "secure". Fix: state benchmark scope, exceptions, errors, and out-of-scope threats.99- Counting errors/not-checked as passes. Fix: preserve result status and block unsupported compliance claims.100- Claiming certification from a local scan. Fix: describe assessment evidence only and defer certification to authorised assessors.101102## Outputs103104| Artefact | Consumer | Acceptance condition |105|---|---|---|106| Scan evidence set | Control owner | Exact content/profile/tailoring, command, XML, human report, timestamp, and host identity are preserved. |107| Qualified findings summary | System owner | Separates pass/fail/error/not-checked/exceptions, prioritises failures, and states coverage limits. |108| Remediation draft/rescan | Change owner | Every change is reviewed/tested with rollback and identical-profile rescan, or remains clearly unexecuted. |109110## Evidence Produced111112| Artefact | Acceptance |113|---|---|114| Compliance scan pack | Contains scanner/content versions, datastream/profile, raw XML, report, status counts, exceptions, errors, Lynis separation, and pre/post evidence where authorised. |115116## Worked Example117118On RHEL 9, confirm `ssg-rhel9-ds.xml`, list the exact profile, run a read-only evaluation, preserve XML and HTML, and report errors separately. Generate remediation only as a draft unless a test-host change is explicitly authorised.119<!-- dual-compat-end -->120121## References122123- [`../../docs/continuous-improvement/linux-product-audit-checklist.md`](../../docs/continuous-improvement/linux-product-audit-checklist.md)124125- [`references/openscap-reference.md`](references/openscap-reference.md) — install SSG, list profiles, evaluate against CIS/STIG/PCI-DSS, generate HTML reports and remediation (bash + Ansible), and pick datastreams per distro.126- [`references/lynis-reference.md`](references/lynis-reference.md) — install, `lynis audit system`, reading the hardening index, prioritizing suggestions, and CI/cron usage.127- [`../linux-auditd-rules/references/auditd-reference.md`](../linux-auditd-rules/references/auditd-reference.md) — applying SSG/CIS audit rulesets via auditd (the rule layer behind a benchmark).128129**This skill is self-contained.** Every command below is standard `oscap` or130`lynis` on its family (see **Distro support** for the install and datastream131substitutions). The `sk-*` script in the **Optional fast path** section is a132convenience wrapper — never required.133134## OpenSCAP: install, list profiles, scan135136```bash137# RHEL family138sudo dnf install openscap-scanner scap-security-guide139# Debian/Ubuntu140sudo apt install openscap-scanner ssg-debderived141142# List the profiles in your distro's datastream (pick the right ds.xml!)143oscap info /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml144145# Evaluate against a CIS profile, writing machine + human reports146sudo oscap xccdf eval \147 --profile xccdf_org.ssgproject.content_profile_cis \148 --results results.xml \149 --report report.html \150 /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml151```152153`results.xml` is the audit-trail artefact; `report.html` is the readable154pass/fail breakdown. STIG, PCI-DSS, and HIPAA profiles live in the same155datastream — list them with `oscap info` and swap the `--profile` ID.156157## OpenSCAP: generate remediation158159```bash160# Bash remediation script from a completed scan161sudo oscap xccdf generate fix \162 --profile xccdf_org.ssgproject.content_profile_cis \163 --fix-type bash \164 --output remediate.sh \165 results.xml166167# Ansible playbook instead168sudo oscap xccdf generate fix \169 --profile xccdf_org.ssgproject.content_profile_cis \170 --fix-type ansible \171 --output remediate.yml \172 results.xml173```174175> Review every generated change. Apply on a **test host** first, then re-scan176> to confirm the score improved before touching production. Full datastream177> selection, profile IDs, and remediation detail in178> [`references/openscap-reference.md`](references/openscap-reference.md).179180## Lynis: quick hardening sweep181182```bash183sudo apt install lynis # dnf install lynis (EPEL on RHEL/Rocky/Alma)184sudo lynis audit system # interactive: score + suggestions185sudo lynis audit system --quiet --logfile /var/log/lynis.log # for cron/CI186187# Results: hardening index + warnings + suggestions188sudo grep -E 'Hardening index|Warning|Suggestion' /var/log/lynis-report.dat189```190191The hardening index is a quick directional score, not a benchmark. Work the192prioritized suggestions, then re-run. Detail in193[`references/lynis-reference.md`](references/lynis-reference.md).194195## Optional fast path (when sk-* scripts are installed)196197Running `sudo install-skills-bin linux-benchmark-scanning` installs:198199| Task | Fast-path script |200|---|---|201| Auto-pick the SSG datastream, run OpenSCAP + Lynis, summarise scores | `sudo sk-benchmark-scan --profile cis` |202203This is an optional read-only wrapper around `oscap` and `lynis` — it scans204and reports, it never remediates. The commands above are the source of truth.205206## Scripts207208This skill installs the following scripts to `/usr/local/bin/`. To install:209210```bash211sudo install-skills-bin linux-benchmark-scanning212```213214| Script | Source | Core? | Purpose |215|---|---|---|---|216| sk-benchmark-scan | scripts/sk-benchmark-scan.sh | yes | Read-only compliance scan on both families: auto-detect the distro/version, locate the matching SSG datastream, run `oscap xccdf eval` against the chosen profile (CIS/STIG/PCI-DSS) into timestamped results.xml + report.html, optionally run `lynis audit system`, and print a pass/fail + hardening-index summary. Never remediates. |