chmod: changing permissions of '...': Operation not permitted (Linux) — how to fix
chmod: changing permissions of 'script.sh': Operation not permitted
chmod: changing permissions of '/mnt/usb/run.sh': Operation not permitted
Quick fix: Check the owner with ls -l file; if it's not you, use sudo chmod ... or sudo chown $USER file. If even root fails, check lsattr file and remove an immutable flag with sudo chattr -i file. On USB/Windows/SMB mounts, set permissions with mount options (uid=, gid=, fmask=, dmask=) instead of chmod.
What it means
chmod calls chmod(2); the kernel returned EPERM. That is different from Permission denied (EACCES, usually about reading a directory) and from Read-only file system (EROFS, see read-only file system).
Start by looking at the file and where it lives:
ls -l script.sh
stat -c '%U:%G %a' script.sh
findmnt -T script.sh # which filesystem and mount options
lsattr script.sh # ext4/xfs/btrfs attributes
Cause 1: you are not the owner
Only the owner of a file (or root) can change its mode — having write permission isn't enough. Files created by sudo, by a Docker container, or by another user are owned by someone else.
sudo chmod +x script.sh
# or take ownership, then chmod normally
sudo chown "$USER":"$USER" script.sh
chmod +x script.sh
For a whole project created by a container running as root:
sudo chown -R "$USER":"$USER" ~/project
Need the right numeric mode? The chmod calculator converts between rwx and octal.
Cause 2: immutable or append-only attribute
If sudo chmod also fails with Operation not permitted, check attributes:
lsattr /etc/resolv.conf
# ----i---------e------- /etc/resolv.conf
i = immutable, a = append-only. Remove it (and add it back later if it was intentional):
sudo chattr -i /etc/resolv.conf
sudo chmod 644 /etc/resolv.conf
Some admins and hardening scripts set +i on purpose; malware sometimes does too. Find out why before removing it on a server.
Cause 3: the filesystem doesn't support Unix permissions
FAT32, exFAT and NTFS (USB sticks, dual-boot partitions) and many SMB/CIFS shares don't keep per-file Unix modes. Permissions are fixed at mount time, so chmod fails or does nothing.
Remount with the owner and modes you want, e.g. for exFAT/vfat:
sudo umount /mnt/usb
sudo mount -o uid=$(id -u),gid=$(id -g),fmask=0022,dmask=0022 /dev/sdb1 /mnt/usb
For CIFS shares, use uid=, gid=, file_mode=0755,dir_mode=0755 in the mount options or /etc/fstab.
If you need executable scripts or real permissions, copy the files to a Linux filesystem (e.g. your home directory) and work there.
Cause 4: WSL and Windows drives
Under WSL, files in /mnt/c/... live on NTFS. Without the metadata option, chmod changes are not stored. Either keep projects inside the Linux filesystem (~/project), or enable metadata in /etc/wsl.conf:
[automount]
options = "metadata,umask=22,fmask=11"
Then run wsl --shutdown from Windows and reopen the terminal.
Cause 5: containers, NFS and rootless setups
- Docker bind mounts: inside the container, files keep the host's UID. A non-root container user can't chmod files owned by another UID. Fix ownership on the host or run the container with
--user $(id -u):$(id -g). - NFS with root_squash: root on the client is mapped to
nobody, sosudo chmodfails on files owned by other users. Run chmod as the owner or on the NFS server. - Rootless Podman/Docker: use
podman unshare chown ...for files created with mapped UIDs.
Check
chmod +x script.sh && ls -l script.sh
If the mode changes, you're done; if the command succeeds but ls -l shows no change, the filesystem is ignoring modes (Cause 3/4).
Last updated 2026-12-05.