هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
dnf install -y openscap-scanner scap-security-guide
oscap info /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml | grep -i 'profile' | head -20
oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_cis_server_l1 --results /root/cis-results.xml --report /root/cis-report.html /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xmlStep by step
- Install the scanner and the content (quick answer). The content file matches the OS:
ssg-rhel9-ds.xml,ssg-rhel8-ds.xml… For Ubuntu use the content from the ComplianceAsCode project releases or Ubuntu's own USG tool. - Choose a profile —
oscap infolists them with their IDs. CIS Level 1 Server is a good start; Level 2 and STIG are stricter. - Scan as root (quick answer, line 3) — takes a few minutes. The exit code is
2when some rules failed — that is normal for a first scan. - Read the report — copy
cis-report.htmlto your laptop (scp) and open it. Each rule showspass,failornotapplicable, the severity, why it matters and how to fix it. Sort by severity; start with high. - Generate a fix — then review it — never run it blind on production:
oscap xccdf generate fix --fix-type ansible --profile xccdf_org.ssgproject.content_profile_cis_server_l1 --output cis-fix.yml /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xmlRemove the rules you cannot apply (for example a separate /tmp partition on an existing server), test the playbook on a copy, then roll it out.
- Document exceptions — some rules do not fit your servers. Write down which and why; a tailoring file (made with SCAP Workbench or
autotailor) removes them from future scans. - New servers compliant from the start — the RHEL installer and Image Builder can apply a profile at install time.
- Scan regularly — a weekly systemd timer, and keep the results to show progress (and to spot drift).
Check that it worked
The report shows the score and the number of failed rules; after the fix and a new scan the score is higher and the high-severity failures are gone or listed as documented exceptions.
Common problems
| Problem | Cause | Fix |
|---|---|---|
No such file for the content | Wrong OS version file, or package missing. | Install scap-security-guide; use the ssg- file of your OS. |
Profile not found | Profile ID typo or not in this content. | Copy the ID from oscap info. |
| Exit code 2 | Some rules failed. | Normal; read the report. |
| Server breaks after the fix | Fix applied without review (SSH, password, mount rules). | Review and test on a copy; apply in small steps. |
Many notchecked rules | Rules that need a person (for example a policy document). | Check those by hand; document them. |
| Scan very slow | Rules that search the whole file system. | Run at night; it is a one-off cost per scan. |
Go further
- Command pages: oscap, ansible.
- Next how-tos: Audit a server with Lynis, Harden the SSH server, Patch a server with security updates, Watch file changes with auditd.
- Learn it: Host security services — OpenSCAP. Full guide: OpenSCAP.
1What is an OpenSCAP profile?
A ready set of rules for one standard (for example CIS Level 1 Server) that oscap checks the server against.
2Why should a generated fix not run straight on production?
Some rules change SSH, passwords or mounts and can lock you out; review and test the fix on a copy first.