Skip to content
DevOps AI ToolKit
Newsletter
All guides
AI for DevOps Security & Hardening By James Joyner IV · · 8 min read

setcap Error: 'Failed to set capabilities on file: Operation not supported' — Cause, Fix, and Troubleshooting Guide

Quick answer

Fix setcap 'Failed to set capabilities ... Operation not supported': the filesystem lacks xattr support (overlay/NFS/tmpfs). Diagnose and fix.

  • #security
  • #hardening
  • #troubleshooting
  • #linux
  • #capabilities
Free toolkit

Fixing errors like this? Get 500 free DevOps AI prompts

500 copy-paste AI prompts for the stack you actually run — one PDF, free.

What this error means

setcap stores file capabilities in a security.capability extended attribute (xattr) on the binary. This error means the target filesystem does not support that xattr — commonly an overlay layer, NFS, some tmpfs/container filesystems, or a mount that strips the needed attributes. Capabilities are the least-privilege alternative to setuid-root, so this blocks a common hardening step.

Failed to set capabilities on file '/usr/local/bin/myapp': Operation not supported

The binary and the syntax may be perfect; the limitation is the filesystem where the file lives.

How it presents

  • sudo setcap 'cap_net_bind_service=+ep' binary fails with Operation not supported.
  • The same command works on /usr/bin (ext4/xfs) but fails inside a container image layer.
  • A Dockerfile RUN setcap ... fails during build on an overlay backend.
  • getcap shows no capabilities after an apparently successful copy.

Tracing the connection

# Which filesystem backs the file, and how is it mounted?
df -T /usr/local/bin/myapp
findmnt -no FSTYPE,OPTIONS -T /usr/local/bin/myapp

# Can this filesystem hold a security xattr at all?
sudo setcap cap_net_bind_service=+ep /usr/local/bin/myapp && \
  getcap /usr/local/bin/myapp || echo "xattr not supported here"

# Compare against a known-good ext4/xfs path
cp /usr/local/bin/myapp /root/myapp && sudo setcap cap_net_bind_service=+ep /root/myapp && getcap /root/myapp

If the copy on /root (ext4/xfs) accepts the capability but the original path does not, the filesystem is the cause.

Network path causes

  • Filesystem without xattr/security namespace support. Overlay upper/lower quirks, older NFS, or a tmpfs that does not carry security.* xattrs.
  • Network filesystem. NFS generally does not support the file-capability xattr.
  • Mount options stripping attributes. A mount with restrictive options or a squashed read-only layer.
  • Building on the wrong layer. setcap in a container build lands on an overlay layer that discards the xattr.
  • 9p / virtiofs shared folders (common in VMs) not passing security.capability through.

Remediation steps

1. Place the binary on an xattr-capable filesystem (ext4/xfs on local disk), then set the capability:

sudo install -m 0755 myapp /usr/local/bin/myapp
sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/myapp
getcap /usr/local/bin/myapp

2. In container builds, set capabilities at runtime, not on an overlay layer that drops the xattr:

# Instead of RUN setcap in the Dockerfile, grant at run time:
docker run --cap-add=NET_BIND_SERVICE myimage
# or for k8s, use securityContext.capabilities.add: ["NET_BIND_SERVICE"]

3. Avoid NFS for capability-bearing binaries — deploy them to local storage on each host.

4. As an alternative to file capabilities, grant the capability to the service via systemd:

# /etc/systemd/system/myapp.service
[Service]
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE

Keeping the path healthy

  • File capabilities are lost on cp across some filesystems and on rebuilds — re-apply as part of deployment, and verify with getcap.
  • Prefer granting the minimal capability (cap_net_bind_service) over setuid-root; do not reach for cap_sys_admin, which is near-root.
  • Container images should grant capabilities at runtime via --cap-add/securityContext, keeping the image itself minimal.
  • systemd AmbientCapabilities avoids filesystem xattr issues entirely and pairs well with a tight CapabilityBoundingSet.
Free download · 368-page PDF

Get 500 Battle-Tested DevOps AI Prompts — Free

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.