Linux Capabilities Audit & Hardening Prompt
Audit POSIX file capabilities and per-process capability sets to find binaries and services that hold more privilege than they need, then drop them — replacing blunt setuid-root with least-privilege capabilities.
- Target user
- Linux admins and security engineers reducing privilege on hosts
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a Linux hardening engineer who treats every setuid-root binary as a liability and reaches for fine-grained capabilities instead. I will provide: - Distro and kernel version - A list of services/binaries of concern (or "audit the whole host") - Whether containers are involved (and the runtime) - The risk posture (internet-facing, multi-tenant, regulated) Produce a capability audit and reduction plan: 1. **Inventory the bounding** — explain the five capability sets (permitted, effective, inheritable, bounding, ambient) in plain terms, then show how to read a running process's sets from `/proc/<pid>/status` (Cap* fields) and decode them with `capsh --decode=`. 2. **Find file capabilities** — `getcap -r / 2>/dev/null` to list every binary with a file capability, and a separate `find / -perm -4000 -type f` sweep for setuid-root. Flag the difference: a binary needing only `cap_net_bind_service` should never be setuid-root. 3. **Map need to grant** — for each flagged binary, identify the *one* capability it actually requires (e.g. `cap_net_raw` for ping, `cap_net_bind_service` for a web server on :80) and how to grant exactly that with `setcap` while removing the setuid bit. 4. **Service-level least privilege** — for systemd units, show `CapabilityBoundingSet=` and `AmbientCapabilities=` so a service starts as non-root yet binds a low port; contrast with `NoNewPrivileges=` and why it interacts with ambient caps. 5. **The dangerous ones** — call out `cap_sys_admin` (the "new root"), `cap_dac_override`, `cap_sys_ptrace`, `cap_setuid` and why their presence usually means the privilege model is wrong. 6. **Containers** — show the default capability set a runtime grants, how to drop all and add back only what's needed, and the audit command to list a container's effective caps. 7. **Verify** — re-run the audit, prove the binary still works with reduced privilege, and confirm no capability was silently inherited. For each finding output: current grant, why it's excessive, the exact `setcap`/unit change, and the residual risk if it can't be removed. End with a prioritized table sorted by blast radius. Bias toward: removing setuid-root entirely, granting the single narrowest capability, and proving function after every change.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Runtime Capability & Ambient Set Audit (getpcaps) Prompt
Audit what Linux capabilities a running process actually holds across its permitted/effective/inheritable/ambient/bounding sets, and decide whether a service is over-privileged or whether a 'permission denied' is a missing capability.
-
Linux fapolicyd Application Allowlisting Prompt
Design, test, and roll out fapolicyd application allowlisting so only trusted binaries and scripts execute, without locking yourself out or breaking legitimate app updates, package installs, and interpreters.
-
Linux USBGuard Device Authorization Policy Prompt
Author and roll out a USBGuard policy that allowlists known USB devices and blocks rogue/BadUSB hardware, without cutting off the keyboard, KVM, or boot devices you need to stay logged in.
-
SetUID/SetGID Binary Audit Prompt
Inventory every setuid and setgid binary on a host, classify each as expected, removable, or suspicious, and propose a least-privilege remediation plan that uses capabilities instead of full root.
More Linux Admins prompts & error guides
Browse every Linux Admins prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.