How to Fix ‘Operation Not Permitted’ Despite Being Root in Linux (chattr)

Administering a Linux server or desktop operating system with superuser privileges (root or via sudo) is traditionally understood to grant absolute administrative authority over files, directories, and processes. However, executing a standard deletion command (rm -rf), attempting to edit a configuration file in nano, or modifying permissions with chmod only to be blocked by the error: “Operation not permitted” creates confusion. In Linux, standard UNIX user/group permission models (read, write, execute) are not the only layer of access control. Advanced filesystem attributes (governed by chattr and lsattr), Linux Security Modules (SELinux or AppArmor), and kernel capability restrictions enforce protections that transcend even the root user. When a file is marked with the immutable attribute (+i) or protected by mandatory access controls, the kernel rejects write attempts regardless of root ownership. This technical guide outlines why root actions are denied and provides practical methods to remove filesystem locks in Linux.

Why Does Root Get ‘Operation Not Permitted’?

Traditional Linux root accounts can override standard 777 or 000 permissions. However, execution is blocked when higher-level security boundaries are engaged:

  • Extended Immutable Attribute (chattr +i): In ext4, XFS, and ext3 filesystems, setting the immutable attribute prevents any user—including root—from modifying, deleting, renaming, or creating symlinks to the file.
  • Append-Only Attribute (chattr +a): The file can only be opened in append mode for writing log entries; overwriting or truncating the file is strictly forbidden.
  • SELinux or AppArmor Mandatory Access Control: Security policies enforcing type enforcement labels that restrict the root user within a specific security domain.
  • Container Capabilities Dropped (Docker / LXC): Inside a Docker container, the root user operates without the CAP_SYS_ADMIN or CAP_LINUX_IMMUTABLE capability, preventing low-level filesystem overrides.
  • Underlying Read-Only Storage Mounts: The volume being mounted as read-only (ro) due to filesystem errors or network share permissions.

Method 1: Inspect Extended Attributes with lsattr

Checking the file's extended attributes reveals whether the immutable or append-only flags are active.

  1. Open your Linux terminal.
  2. Run the lsattr utility against the problematic file:
    lsattr /path/to/file
  3. Examine the output flags. Look for the letter i or a:
    ----i---------e---- /path/to/file
  4. The presence of i confirms that the file has the immutable attribute enabled, which blocks all deletion and modification commands.

Method 2: Remove the Immutable Attribute Using chattr -i

Clearing the immutable flag using the change attribute command restores standard root permissions.

  1. Execute the following command with superuser privileges:
    sudo chattr -i /path/to/file
  2. If an entire directory structure is locked recursively, use the -R flag:
    sudo chattr -R -i /path/to/directory/
  3. If the file was locked in append-only mode (showing a in lsattr), remove it with:
    sudo chattr -a /path/to/file
  4. Verify that the attribute has been cleared by running lsattr /path/to/file again.
  5. You can now delete, edit, or modify the file using standard rm, nano, or chmod commands.

Method 3: Inspect and Adjust SELinux Security Contexts

On enterprise distributions such as Red Hat Enterprise Linux (RHEL), Rocky Linux, AlmaLinux, and Fedora, SELinux policies enforce mandatory access controls.

  1. Check whether SELinux is currently enforcing policies:
    getenforce
  2. If it returns Enforcing, view the security context of the file:
    ls -Z /path/to/file
  3. Check the audit log to confirm if SELinux blocked the action:
    sudo ausearch -m avc -ts recent
  4. Restore the default SELinux context for the file:
    sudo restorecon -v /path/to/file
  5. If necessary for testing, temporarily switch SELinux to permissive mode:
    sudo setenforce 0

Method 4: Check AppArmor Profiles on Ubuntu and Debian

On Ubuntu and Debian systems, AppArmor profiles confine specific services (such as MySQL, Nginx, or Docker) from touching files outside their designated paths.

  1. Inspect loaded AppArmor profiles:
    sudo aa-status
  2. If the target service or directory is restricted, place the profile into complain mode for testing:
    sudo aa-complain /etc/apparmor.d/usr.sbin.servicename
  3. Check system logs for denied operations:
    sudo dmesg | grep -i apparmor

Method 5: Check Docker Container Capabilities

If you are operating inside a Docker container as root, the container runtime restricts Linux capabilities by default.

  1. Inside the container, check available capabilities:
    capsh --print
  2. If cap_linux_immutable is missing, the container root cannot modify immutable files.
  3. Launch the container with elevated capabilities from the host system:
    docker run --cap-add=LINUX_IMMUTABLE ...
  4. Or run the container with full privileges: --privileged.

For more Linux system administration tutorials and command-line guides, explore our Digitash Terminal section.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.