Guide: chmod Operation not permitted (Even as Root) in Linux
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
lsattr <file> and clear attributes using sudo chattr -i <file>sudo mount -o remount,rw / or verify SELinux contextEncountering 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
Step 1: Inspect Extended Attributes with lsattr
Standard
ls -lcommands only expose conventional POSIX permission bits. Extended kernel flags requirelsattr:BASH# Inspect extended filesystem attributes lsattr /path/to/file # Typical output showing immutable bit: # ----i---------e---- /path/to/file (Letter 'i' denotes immutable) -
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
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
Step 4: Check Filesystem Mount Status
If
lsattrreports 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 withsudo chattr +i /etc/resolv.conf. - Audit unauthorized attribute modifications: Malware scripts frequently apply
+iflags to prevent administrative deletion.