Linux EPERMMedium

chmod: operation not permitted error in Linux: causes and solution

Article explains why 'chmod: operation not permitted' occurs in Linux and provides step-by-step solutions: from simple sudo usage to changing mount parameters and file attributes.

Updated at February 17, 2026
5-10 min
Easy
FixPedia Team
Применимо к:Linux (any distribution)chmod (coreutils 8.32+)

What the Error Code Means

The error chmod: changing permissions of '<file>': Operation not permitted (EPERM code) occurs when the chmod command cannot change the access attributes (permissions) of a file or directory. In Linux, this is a system error indicating that the operation is forbidden for the current user or by the filesystem.

The full error text typically looks like this:

chmod: changing permissions of 'example.txt': Operation not permitted

The error blocks the execution of the chmod command and prevents setting new permissions (e.g., 755, 644, or special bits like setuid).

Causes

  1. Insufficient permissions — you are not the file owner and not the superuser (root). Only the file owner or root can change its permissions.
  2. Filesystem with restrictions — the file is located on a partition mounted with options like noexec (execution forbidden), nosuid (setuid/setgid forbidden), or ro (read-only). This is typical for USB drives, network shares (NFS), or protected partitions.
  3. Immutable or append-only attribute — the file is protected by chattr +i (immutable) or chattr +a (append-only) flags. These flags block any changes, including permissions, even for root.
  4. Incorrect use of setuid/setgid — attempting to set the s bit (setuid/setgid) on:
    • a non-executable file (missing x for owner/group);
    • a directory (setuid/setgid on directories is ignored or forbidden).
  5. Attempting to change permissions on a symbolic link — if you are not root, chmod by default tries to change permissions on the link's target file, not the link itself. If the target file is not owned by you, EPERM will occur.

Method 1: Using sudo (if you are not the owner)

If the file belongs to another user (e.g., root), use sudo to run the command as the superuser.

  1. Check the file owner:
    ls -l /path/to/file
    

    Example output:
    -rw-r--r-- 1 root root 1024 Feb 17 10:00 example.txt
    

    Here the owner is root.
  2. Run chmod with sudo:
    sudo chmod 644 /path/to/file
    

    Or, to set setuid (if needed):
    sudo chmod u+s /path/to/executable_file
    

⚠️ Important: Use sudo only for trusted files. Changing permissions on system files can disrupt OS operation.

Method 2: Changing the file owner (if you have sudo rights)

If you are an administrator and want the user to be able to change permissions themselves, change the file's owner.

  1. Change the owner to the desired user (e.g., alex):
    sudo chown alex /path/to/file
    

    You can also change the group simultaneously:
    sudo chown alex:developers /path/to/file
    
  2. Now user alex can change permissions without sudo:
    chmod 755 /path/to/file
    

Method 3: Checking and modifying mount parameters

If the file is on an external drive (USB, network disk) or a separate partition, check how the filesystem is mounted.

  1. Find the file's mount point:
    findmnt /path/to/file
    

    Example output:
    TARGET SOURCE    FSTYPE OPTIONS
    /mnt/usb /dev/sdb1 vfat   rw,noexec,nosuid,nodev,relatime,uid=1000,gid=1000,...
    
  2. If the OPTIONS column contains noexec, nosuid, or ro (read-only), you need to remount the partition:
    sudo mount -o remount,rw,exec /dev/sdb1 /mnt/usb
    

    For a permanent solution, edit /etc/fstab and remove noexec/nosuid from the options for the relevant partition.

Method 4: Removing immutable/append-only attributes

If the file is protected by chattr flags, remove them before changing permissions.

  1. Check the attributes:
    lsattr /path/to/file
    

    Example output:
    ----i--------e-- /path/to/file
    

    The letter i means immutable.
  2. Remove the attribute (requires sudo):
    sudo chattr -i /path/to/file
    

    For append-only (a):
    sudo chattr -a /path/to/file
    
  3. Now change the permissions:
    sudo chmod 644 /path/to/file
    

💡 Tip: The chattr flags are often used to protect critical system files (e.g., /etc/passwd, /etc/shadow). Be careful when removing them.

Method 5: Checking setuid/setgid and executability

If the error occurs when setting special bits (s or S), check the file's executability.

  1. Ensure the file is executable (has x for the owner):
    ls -l /path/to/file
    

    Example of correct output for setuid:
    -rwsr-xr-x 1 root root 12345 Feb 17 10:00 program
    

    The letter s in the owner's position (instead of x) indicates setuid.
  2. If x is missing, add it:
    sudo chmod u+x /path/to/file
    

    Then set setuid:
    sudo chmod u+s /path/to/file
    
  3. For setgid (the s bit in the group), similarly:
    sudo chmod g+x /path/to/file
    sudo chmod g+s /path/to/file
    

Prevention

  • Avoid changing permissions on system files without explicit need. Use sudo mindfully.
  • When working with external media, mount them with rw,exec options (if you need to execute files) and without nosuid if setuid is not required.
  • Do not set the immutable attribute (chattr +i) on files that may require permission changes in the future.
  • Check executability before setting setuid/setgid. Remember: setuid/setgid require the file to be executable for the relevant category (owner/group).
  • Regularly check file ownership, especially in directories used by multiple users. Use ls -l for auditing.

F.A.Q.

Why does the 'chmod: operation not permitted' error occur in Linux?
How to fix 'chmod: operation not permitted' without sudo?
Can the 'operation not permitted' error occur when setting setuid?
What to do if the file is on an external USB drive and chmod doesn't work?

Hints

Determine current file owner and permissions
Use sudo to change permissions (if you're not the owner)
Check file attributes (immutable, append-only)
Check filesystem mount parameters
Ensure setuid/setgid bits are correct

Did this article help you solve the problem?

FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community