Join our Newsletter — 33% off our NHI Course
Home› Guides› Linux Capabilities Guide: Dropping Root Privileges With CAP_…
Guide Endpoint Security

Linux Capabilities Guide: Dropping Root Privileges With CAP_ Sets and File Capabilities

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 27 October 2026 16 min read
On this page

Most Linux services that run as root need only one or two of the privileges root carries, yet they receive all of them. Linux capabilities split the power of UID 0 into roughly forty distinct units, such as CAP_NET_BIND_SERVICE for binding ports below 1024 or CAP_DAC_OVERRIDE for bypassing file permission checks, so a service account can hold exactly what it needs and nothing more. Used well, capabilities remove root from daemons, containers and scheduled jobs. Used carelessly, they create quiet escalation paths: a file capability on an interpreter or a container started with CAP_SYS_ADMIN is root under another name. This guide is for Linux engineers, platform teams and auditors who need to apply capabilities with systemd, containers and file attributes, and to find the ones already granted.

Key takeaways

  • Capabilities are privileges, not permissions. Each CAP_ name bypasses a specific kernel check, so a process with the right capability can ignore file modes, change UIDs or load kernel modules regardless of who owns it.
  • Five sets decide what a process can do. Permitted, effective, inheritable, bounding and ambient interact at every execve(), and the bounding set is the ceiling you control from systemd and container runtimes.
  • Some capabilities are root equivalents. CAP_SYS_ADMIN, CAP_SYS_MODULE, CAP_SETUID, CAP_DAC_OVERRIDE, CAP_SYS_PTRACE and CAP_SETFCAP each lead to full root in practice and should be treated as privileged access.
  • File capabilities are an audit blind spot. They live in the security.capability extended attribute, are invisible to ls and to SUID searches, and need their own inventory with getcap.
  • Prefer service-level grants to file grants. AmbientCapabilities= with a non-root User= and a tight CapabilityBoundingSet= scopes the privilege to one unit, while a file capability applies to anyone who can execute the binary.

How identity and access work in Linux capabilities

Classic Unix had two classes of process: privileged (effective UID 0) and everyone else. The capabilities(7) model, available since Linux 2.2 and completed with per-thread bounding sets in 2.6.25 and ambient capabilities in 4.3, attaches privileges to threads and to executable files instead of to the UID alone. The kernel checks the thread's effective set when a privileged operation is attempted. The identity of the account still matters for ordinary discretionary access control, but a capability lets the process step around specific checks.

The thread capability sets

SetWhat it doesPractical meaning for defenders
PermittedThe limiting superset of what the thread may make effective. A capability dropped from it cannot be regained except through a set-UID-root program or a file with capabilities.What the process could switch on at any time.
EffectiveThe set the kernel actually checks for each privileged operation.What the process is using right now.
InheritablePreserved across execve(); added to the new program's permitted set only where the file's inheritable set has matching bits.Rarely useful on its own; a prerequisite for ambient capabilities.
BoundingLimits the capabilities gained during execve(). Capabilities can be dropped from it but never restored.The ceiling. Set it in systemd units and container runtimes so nothing below can exceed it.
AmbientSince Linux 4.3, preserved across execve() of an unprivileged program. A capability can be ambient only if it is both permitted and inheritable.The mechanism that lets a non-root service keep CAP_NET_BIND_SERVICE after it starts its binary.

File capabilities and what happens at execve()

An executable can carry a permitted mask, an inheritable mask and a single effective bit, stored in the security.capability extended attribute. Writing that attribute requires CAP_SETFCAP. At execve() the kernel computes the new permitted set as (thread inheritable AND file inheritable) OR (file permitted AND bounding set) OR the ambient set. If the file's effective bit is set, the new permitted set also becomes effective. When root executes a program, the file sets are treated as all ones, so root receives everything the bounding set allows: this is why the bounding set, not the UID, is the real control for root-run services. Executing a set-UID, set-GID or file-capability binary clears the ambient set.

Linux 4.14 added version 3 namespaced file capabilities, which record the root user ID of the user namespace that set them. A version 3 capability is honoured only when the binary runs in a user namespace whose UID 0 maps to that stored ID, which stops a container from planting a file capability that works on the host. In text form, cap_net_bind_service=ep raises the capability in effective and permitted and leaves inheritable lowered (cap_text_formats(7) uses cap_fowner=ep as its example).

Securebits and no_new_privs

  • SECBIT_KEEP_CAPS: lets a UID 0 thread keep its permitted set when it switches all UIDs to non-zero; always cleared on execve().
  • SECBIT_NOROOT: the kernel grants no capabilities when a set-UID-root program runs or when UID 0 executes a program. Combined with its locked flag it turns root into an ordinary user for capability purposes.
  • SECBIT_NO_CAP_AMBIENT_RAISE: prevents raising ambient capabilities; the locked variants make each bit irreversible.
  • no_new_privs: a per-process attribute (set by systemd NoNewPrivileges=, Docker no-new-privileges and Kubernetes allowPrivilegeEscalation: false) that stops execve() from granting privilege through set-UID, set-GID or file capabilities.

Admin roles and privileged access

Not every capability carries the same risk. The capabilities(7) page itself flags CAP_SYS_ADMIN as overloaded and tells kernel developers "Don't choose CAP_SYS_ADMIN if you can possibly avoid it!"; CAP_BPF and CAP_PERFMON were split out of it in Linux 5.8 for that reason. Classify capabilities by blast radius and govern the top tier as you would sudo rights to root. See the Unix and Linux Privileged Access Guide.

CapabilityWhat it bypassesRisk tierWhy
CAP_SYS_ADMINMounts, namespaces, many device and kernel operationsRoot equivalentToo broad to constrain; the common container escape enabler
CAP_SYS_MODULELoading and unloading kernel modulesRoot equivalentArbitrary kernel code
CAP_SYS_RAWIOI/O ports, /dev/mem, /proc/kcoreRoot equivalentDirect memory and hardware access
CAP_SETUID / CAP_SETGIDArbitrary UID and GID changesRoot equivalentThe process can simply become UID 0
CAP_DAC_OVERRIDEFile read, write and execute checksRoot equivalentCan rewrite /etc/shadow, sudoers or root's keys
CAP_DAC_READ_SEARCHFile read and directory search checks, open_by_handle_at()HighReads shadow hashes, private keys and keytabs
CAP_SYS_PTRACETracing arbitrary processes, sensitive /proc dataHighInject into or read memory of root processes
CAP_SETFCAP / CAP_SETPCAPSetting file capabilities; changing capability setsHighGrants capabilities to other binaries
CAP_CHOWN / CAP_FOWNERFile ownership and owner-match checks, ACLsHighTake ownership of sensitive files
CAP_NET_ADMINInterfaces, firewall rules, routing, promiscuous modeMedium to highCan disable host firewalling or redirect traffic
CAP_NET_RAWRAW and PACKET socketsMediumPacket crafting and sniffing on shared networks
CAP_BPF / CAP_PERFMONPrivileged BPF and performance monitoringMedium to highKernel observability, sometimes combined for powerful tooling
CAP_NET_BIND_SERVICEBinding ports below 1024LowThe usual reason a web or DNS daemon was run as root
  • Treat root-equivalent grants as privileged access: require an owner, a change record and periodic review for any unit, container or file holding a top-tier capability, exactly as for a sudoers rule. See the sudo and sudoers Security Guide.
  • Keep humans off capabilities: capabilities are for services. Interactive administrators should use sudo or a PAM tool with session logging, not a shell carrying ambient capabilities (pam_cap can do this, which is exactly why it needs review).
  • Remember root still has everything: dropping capabilities only helps if the process cannot regain them. A root service with a full bounding set can re-raise any capability; reduce the bounding set or run as a non-root user.

Integrations, API tokens and service accounts

The main identity value of capabilities is that a service account can stop being root. A dedicated non-root account with one ambient capability is easier to reason about, cannot write to most of the filesystem and does not inherit root's access to secrets. See the Linux Service Accounts and Keytab Management Guide.

Pattern 1: systemd unit with ambient capabilities (preferred)

[Service]
User=webapp
Group=webapp
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
NoNewPrivileges=yes
  • AmbientCapabilities= (systemd 229 and later) adds the capability to the ambient set; systemd adds keep-caps to SecureBits= automatically so the capability survives the switch to User=.
  • CapabilityBoundingSet= keeps only the listed capabilities and removes the rest, so nothing the service executes can ever gain more. A ~ prefix inverts the list (deny-list form), which is weaker and should be the exception.
  • NoNewPrivileges=yes stops children gaining privilege through set-UID binaries or file capabilities. It does not cover jobs started on request via at, crontab or systemd-run.
  • DynamicUser=yes allocates a transient UID from 61184 to 65519 and implies NoNewPrivileges=, RestrictSUIDSGID=, ProtectSystem=strict and ProtectHome=read-only, which is a strong default for stateless services.
  • Commands prefixed with + run with full privileges and ignore these settings; flag any ExecStart=+ or ExecStartPre=+ in review.

See the systemd Service Hardening Guide for the wider sandboxing options.

Pattern 2: file capabilities (use sparingly)

setcap cap_net_bind_service=ep /usr/local/bin/app lets any user who can execute the file bind a low port. setcap -v verifies a grant, setcap -r removes the attribute, and setcap(8) notes that setting an empty set is not the same as removing it. File grants are acceptable for a single-purpose compiled binary owned by root, mode 0755 or tighter, on a filesystem users cannot write. They are never acceptable on interpreters (python, perl, node, ruby), shells, editors, tar, or anything that can read or write arbitrary files: a file capability of CAP_SETUID on an interpreter is a published escalation path, documented as the "capabilities" technique in the Linux Privilege Escalation Techniques Guide.

Pattern 3: containers

Container runtimes start every container with a default bounding set. The Moby (Docker Engine) default is 14 capabilities: CHOWN, DAC_OVERRIDE, FSETID, FOWNER, MKNOD, NET_RAW, SETGID, SETUID, SETFCAP, SETPCAP, NET_BIND_SERVICE, SYS_CHROOT, KILL and AUDIT_WRITE. The Kubernetes Pod Security Standards then set two levels:

ControlBaselineRestricted
Privileged containersForbiddenForbidden
capabilities.addOnly AUDIT_WRITE, CHOWN, DAC_OVERRIDE, FOWNER, FSETID, KILL, MKNOD, NET_BIND_SERVICE, SETFCAP, SETGID, SETPCAP, SETUID, SYS_CHROOTOnly NET_BIND_SERVICE
capabilities.dropNot requiredMust include ALL
allowPrivilegeEscalationNot restrictedMust be false

The defensible default is drop: ["ALL"] with an explicit add list per workload, a non-root user and allowPrivilegeEscalation set to false. Privileged mode and CAP_SYS_ADMIN are the usual preconditions for MITRE ATT&CK T1611 Escape to Host. See the Container Runtime Security Guide.

Choosing between the patterns

SituationChooseTrade-off
Long-running daemon managed by systemdAmbientCapabilities= plus CapabilityBoundingSet=Scoped to the unit; needs systemd 229 or later
Binary started by users, cron or another supervisorFile capability on a dedicated, root-owned binaryApplies to every caller; must be inventoried
Containerised workloadDrop ALL, add the minimum in the pod or run specSome images assume root and need rebuilding
Legacy software that needs root brieflyStart as root, drop to a user and a reduced bounding set in code (libcap or libcap-ng)Depends on developer discipline; verify with /proc
Port binding onlyConsider a reverse proxy or socket activation insteadNo capability at all for the application

Small estates can usually standardise on the systemd pattern and ban file capabilities outside a short allow-list. Large estates need the allow-list in configuration management, admission control for containers and a scheduled inventory, because packages and images will keep adding grants.

Logging and detection

  • Inventory file capabilities: getcap -r / 2>/dev/null lists every file carrying security.capability. Compare the output against an approved baseline per image or role; on most distributions only a handful of binaries (often ping or a few network tools) carry capabilities.
  • Inspect running processes: the CapPrm, CapEff, CapBnd and CapAmb lines in /proc/<pid>/status show each set as a hexadecimal mask; capsh --decode=<hex> converts it to names, and pscap from libcap-ng lists processes with capabilities.
  • Audit capability changes: add auditd rules on the setxattr, lsetxattr, fsetxattr and removexattr syscall family so every new file capability is logged with the acting user, and watch execution of setcap itself. See the Linux Logging and auditd for Defenders Guide.
  • Review unit files: systemd-analyze capability lists the capabilities the local kernel knows; systemd-analyze security <unit> scores a unit's exposure including its bounding set. Track changes to CapabilityBoundingSet= and AmbientCapabilities= in configuration management.
  • Container admission: enforce Pod Security Admission at restricted where possible and alert on any workload admitted with privileged: true, SYS_ADMIN, SYS_PTRACE, NET_ADMIN or SYS_MODULE.
  • Behavioural signals: an unprivileged account process suddenly running with UID 0, or setcap executed outside a deployment pipeline, should go to the SOC. See the Linux Detection and Response Guide.

Metrics that show it is working

  • Root-run services: percentage of systemd services and containers running as UID 0, trending down.
  • Unapproved file capabilities: count of getcap findings not on the allow-list (target zero).
  • Bounded units: percentage of custom units with an explicit CapabilityBoundingSet=.
  • Drop ALL coverage: percentage of container workloads with drop ALL and allowPrivilegeEscalation false.
  • Root-equivalent grants: number of workloads holding a top-tier capability, each with a named owner and review date.

Hardening baseline

Roll out capability reduction service by service, testing each change before it is enforced.

  1. Inventory: list root-run services (ps -eo user,pid,comm, systemctl), container specs and every file capability. Record the owner and purpose of each.
  2. Discover what each service really needs: on a test host, start the service with CapabilityBoundingSet= empty and a non-root User=, then add back only the capabilities whose absence produces EPERM errors in the journal or strace output. Most web, proxy and DNS daemons need only CAP_NET_BIND_SERVICE, and many need nothing.
  3. Pilot: apply the drop-in (systemctl edit <unit>) to a pilot ring, monitor functional checks and error logs for a full business cycle, including log rotation, reloads and certificate renewal, which often need extra rights.
  4. Enforce: roll the drop-in through configuration management. For containers, move namespaces from Pod Security Admission warn and audit modes to enforce once violations are cleared.
  5. Remove file capabilities that are no longer needed: setcap -r on each unapproved file, and fix the packaging or image build so it does not return.
  6. Roll back safely: a drop-in can be removed with systemctl revert <unit> followed by a restart; keep the previous container spec version in Git for a quick redeploy. Never roll back by switching the service to root permanently: open a time-boxed exception instead.

Framework mapping

FrameworkReferenceHow capabilities apply
NIST SP 800-53 Rev. 5AC-6 Least Privilege, AC-6(1), AC-6(9), CM-7 Least Functionality, CM-6 Configuration SettingsMinimal capability sets, logged privileged functions, baseline-controlled unit files
NIST CSF 2.0PR.AA-05, PR.PS-01Entitlements defined and reviewed; configuration management applied
CIS Controls v8.14.1 Secure configuration process, 5.4 Restrict administrator privileges, 6.8 Role-based access controlCapabilities as a documented, reviewed privilege
MITRE ATT&CKT1548 Abuse Elevation Control Mechanism, T1548.001 Setuid and Setgid, T1068 Exploitation for Privilege Escalation, T1611 Escape to HostFewer capabilities shrink the escalation and escape paths these techniques rely on

Pair capabilities with mandatory access control and syscall filtering for depth: see the SELinux Guide, the AppArmor Guide and the seccomp Guide.

Common misconfigurations

  • Dropping from effective but not from permitted or bounding: the process can raise the capability again. Verify with CapPrm and CapBnd in /proc, not just CapEff.
  • File capabilities on interpreters and general tools: cap_setuid on python or cap_dac_read_search on tar gives any local user root or read access to every file. These are often left behind by a developer fixing a permissions error.
  • Replacing root with CAP_SYS_ADMIN: teams report "no longer runs as root" while granting the one capability that is nearly root. The same applies to adding SYS_ADMIN to a container to make a mount or FUSE work.
  • Deny-list bounding sets: CapabilityBoundingSet=~CAP_SYS_MODULE still leaves dozens of capabilities, and new kernel capabilities are allowed by default. Prefer allow-lists.
  • Forgetting the + prefix and helper commands: an ExecStartPre=+ script runs fully privileged, and so can jobs launched via at, cron or systemd-run, which NoNewPrivileges= does not cover.
  • SUID scans that miss capabilities: audits that search only for mode 4000 files miss security.capability entirely, and backup or copy tools that do not preserve extended attributes silently drop or fail to restore grants, producing drift between hosts.

Practitioner checklist

  • Run getcap -r / on every image and host role and keep an approved allow-list with owners.
  • Remove file capabilities from interpreters, shells, editors and archive tools immediately.
  • Classify CAP_SYS_ADMIN, CAP_SYS_MODULE, CAP_SYS_RAWIO, CAP_SETUID, CAP_SETGID, CAP_DAC_OVERRIDE, CAP_SYS_PTRACE and CAP_SETFCAP as root-equivalent and review them like sudo rights.
  • Convert root-run systemd services to a non-root User= with AmbientCapabilities= and an allow-list CapabilityBoundingSet=.
  • Set NoNewPrivileges=yes (or DynamicUser=yes) unless a service has a documented need for set-UID helpers.
  • Run containers with drop ALL, explicit adds, a non-root user and allowPrivilegeEscalation false; enforce Pod Security Admission restricted where workloads allow.
  • Log setxattr-family syscalls and setcap execution with auditd and forward them to the SIEM.
  • Check CapPrm and CapBnd in /proc for each hardened service after every release.
  • Report the five metrics above monthly and track exceptions with expiry dates.

Standards and references

Related NHI Mgmt Group resources: Linux Privilege Escalation Techniques Guide · Linux Server Hardening Guide · systemd Service Hardening Guide · Least Privilege Techniques Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 27 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.