How to Fix ‘chmod: changing permissions: Operation not permitted’ in Linux

The chmod command is the cornerstone of Unix and Linux system security, governing read, write, and execute permissions across files and directories. However, running a command such as chmod +x script.sh or chmod 755 /var/www/html can abruptly fail with the error message: ‘chmod: changing permissions of ‘filename’: Operation not permitted’. Even executing the command with sudo or as the root superuser frequently encounters the exact same failure. Understanding file ownership boundaries, extended attributes, and filesystem mount configurations is essential to resolving this permission block.

Why Does ‘Operation Not Permitted’ Occur During chmod?

Unlike a standard ‘Permission denied’ error (which simply indicates your user account lacks write permissions), ‘Operation not permitted’ signifies that the Linux kernel is actively preventing modification due to filesystem flags or ownership restrictions. Common causes include:

  • File Ownership Mismatch: Under POSIX standards, only the actual owner of a file (or the root superuser) is permitted to modify its mode bits. A user with group write access cannot execute chmod on files owned by another user.
  • Immutable Extended File Attributes: The file is protected by the immutable attribute (+i) or append-only attribute (+a) via chattr, which forbids even root from altering permissions or modifying content.
  • Read-Only Mounted Filesystems: The underlying storage volume or network share is mounted with the ro (read-only) flag, or an underlying disk error forced the kernel into emergency read-only protection.
  • Non-POSIX Filesystems (FAT32, exFAT, NTFS): Storage drives formatted in Windows filesystems mounted without Linux permission emulation support. Native POSIX mode bits do not exist on FAT or NTFS.
  • SELinux or AppArmor Security Modules: Mandatory Access Control (MAC) security policies enforcing strict execution constraints on specific system directories.

Step 1: Check File Ownership and Use Sudo

In Linux, having write access to a file does not grant permission to change its mode bits unless you own the file.

  1. Inspect the current owner and group of the file:
    ls -l filename
  2. If the owner listed is another user (e.g., www-data or root), running chmod as your normal user will return Operation not permitted.
  3. If you have administrative rights, invoke the command using sudo:
    sudo chmod 755 filename
  4. Alternatively, change ownership to your user account first using chown:
    sudo chown $USER:$USER filename
    chmod 755 filename

Step 2: Check for and Remove Immutable Attributes with lsattr and chattr

If even sudo chmod fails with Operation not permitted, the file almost certainly possesses the immutable attribute.

  1. Inspect the extended attributes of the target file using lsattr:
    lsattr filename
  2. Look for the letter i (immutable) or a (append-only) in the output:
    ----i---------e---- filename
  3. When the i attribute is present, the kernel blocks all permission adjustments, renaming, and file deletion, even by root.
  4. Remove the immutable flag using chattr -i:
    sudo chattr -i filename
  5. If working with an entire directory tree, remove the attribute recursively:
    sudo chattr -R -i /path/to/directory
  6. Execute your original chmod command again. It will now succeed immediately.

Step 3: Verify Filesystem Mount Options (Read-Only Status)

Filesystems mounted in read-only mode cannot accept metadata or permission updates.

  1. Check how the partition hosting your file is currently mounted:
    mount | grep $(df -P filename | tail -1 | cut -d' ' -f1)
  2. Check the mount flags enclosed in parentheses. If you see ro instead of rw, the volume is mounted read-only.
  3. Remount the filesystem in read-write mode:
    sudo mount -o remount,rw /mount/point
  4. If the filesystem was automatically remounted read-only due to underlying sector errors, inspect kernel logs with dmesg | tail -n 20 and schedule an fsck disk check.

Step 4: Handle External USB Drives Formatted in FAT32, exFAT, or NTFS

Windows filesystems do not support POSIX file mode bits (755, 644, etc.). Running chmod on files inside a mounted FAT32 or NTFS USB drive always triggers an error.

  1. To control permissions on FAT32, exFAT, or NTFS drives, permissions must be defined at mount time via fmask and dmask options.
  2. Remount the drive specifying universal read/write/execute permissions:
    sudo mount -o remount,uid=1000,gid=1000,fmask=0022,dmask=0022 /media/user/DRIVENAME
  3. All files on the volume will immediately reflect the desired executable and read permissions without needing individual chmod invocations.

Get the best tech tips delivered straight to your inbox.

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