Home » Guide: chmod Operation not permitted (Even as Root) in Linux
Systems & Servers

Guide: chmod Operation not permitted (Even as Root) in Linux

✨ Quick Answer

Encountering chmod: changing permissions of 'file': Operation not permitted or chown: changing ownership of 'file': Operation not permitted while executing commands as superuser root indicates the file is locked by Linux kernel extended filesystem attributes or the storage partition has degraded to Read-Only mode.

Quick Diagnostics

Cause
File protected by kernel immutable (+i) or append-only (+a) filesystem attribute
Solution
Check with lsattr <file> and clear attributes using sudo chattr -i <file>
Cause
Underlying filesystem mounted in Read-Only (ro) mode following disk I/O errors
Solution
Remount read-write via sudo mount -o remount,rw / or verify SELinux context

Encountering chmod: changing permissions of 'file': Operation not permitted or chown: changing ownership of 'file': Operation not permitted while executing commands as superuser root indicates the file is locked by Linux kernel extended filesystem attributes or the storage partition has degraded to Read-Only mode.

Step-by-Step Solution

  1. 1

    Step 1: Inspect Extended Attributes with lsattr

    Standard ls -l commands only expose conventional POSIX permission bits. Extended kernel flags require lsattr:

    BASH
    # Inspect extended filesystem attributes
    lsattr /path/to/file
    
    # Typical output showing immutable bit:
    # ----i---------e---- /path/to/file  (Letter 'i' denotes immutable)
    
  2. 2

    Step 2: Clear Immutable Flags with chattr

    As superuser, strip the immutable and append-only flags:

    BASH
    # Remove immutable (-i) and append-only (-a) flags
    sudo chattr -i /path/to/file
    sudo chattr -a /path/to/file
    
    # Recursively clear across an entire directory tree:
    sudo chattr -R -i /path/to/directory
    
  3. 3

    Step 3: Apply Desired Permissions via chmod / chown

    With the kernel lock removed, mutate permissions normally:

    BASH
    # Grant standard file read/write permissions
    sudo chmod 644 /path/to/file
    
    # Update ownership
    sudo chown user:group /path/to/file
    
  4. 4

    Step 4: Check Filesystem Mount Status

    If lsattr reports no flags yet modification is denied, verify partition write availability:

    BASH
    # Inspect root partition mount options
    mount | grep -i " / "
    
    # Remount filesystem read-write
    sudo mount -o remount,rw /
    

❓ Frequently Asked Questions (FAQ)

Does the immutable flag (+i) block root?

Yes. The immutable flag is enforced directly by the Linux kernel VFS layer. No process—even UID 0—can delete or mutate the file until chattr -i is issued.

Does chattr work on FAT32 or NTFS mounts?

No. Extended attributes are exclusive to native Linux filesystems such as ext4, XFS, and Btrfs.

Prevention Advice

Recommended security practices:

  • Leverage immutability for critical security files: Protect critical infrastructure files (such as /etc/resolv.conf) against rogue daemon overrides with sudo chattr +i /etc/resolv.conf.
  • Audit unauthorized attribute modifications: Malware scripts frequently apply +i flags to prevent administrative deletion.