Modifying user and group ownership of files and directories using the chown command in Linux is a routine administrative task. However, system administrators and developers frequently encounter the terminal error: “chown: changing ownership of ‘/path/to/file’: Operation not permitted”—even when prefixing the command with sudo or executing directly as the root superuser. In Linux, ownership modification is strictly governed by POSIX security semantics, kernel capability sets (such as CAP_CHOWN), filesystem mount options, and extended attributes. When immutable file flags are set, underlying filesystems are mounted read-only or with permission restrictions (such as NFS, FAT32, or NTFS), or SELinux policies restrict DAC overrides, chown aborts with an EPERM error code. This guide details how to diagnose permission barriers and resolve ownership modification failures.
What Causes the ‘Operation Not Permitted’ Error in chown?
Unlike standard permission denied errors (EACCES), “Operation not permitted” (EPERM) indicates an architectural or filesystem-level restriction. Key root causes include:
- Non-Root User Constraints: Unprivileged users attempting to change file ownership. In Linux, standard users cannot “give away” files to another user, even if they own the file.
- Filesystem Immutable Attributes: The file or directory having the
+i(immutable) or+a(append-only) extended attribute set viachattr. - Non-POSIX External Filesystems: Storage devices formatted as FAT32, exFAT, or NTFS lacking native Linux user ID (UID) and group ID (GID) inode fields.
- NFS Root Squashing: Network File System (NFS) shares mapping remote root requests to an unprivileged
nobodyaccount. - Dropped Linux Capabilities in Containers: Docker or LXC containers running without the
CAP_CHOWNcapability enabled.
Step 1: Verify Superuser Privileges
In standard POSIX environments, only the root user possesses the kernel capability to assign files to different user accounts.
- If you executed
chownas a normal user:chown user:group filename - The command will fail immediately with Operation not permitted. Standard users may only change a file’s group to another group they belong to (via
chgrp). - Prefix the command with
sudoto invoke superuser privileges:sudo chown user:group filename - If the error persists even under
sudo, proceed to check extended attributes and filesystem mount configurations below.
Step 2: Inspect and Remove Immutable File Flags (chattr)
Files protected by the immutable flag cannot be modified, deleted, renamed, or have their ownership altered by any user, including root.
- Inspect the extended attributes of the target file using
lsattr:lsattr /path/to/file - Review the output flags:
- If you observe an
i(e.g.----i---------e---- /path/to/file), the file is immutable. - If you observe an
a, the file is append-only.
- If you observe an
- Remove the immutable flag using
chattr -iwith root privileges:sudo chattr -i /path/to/file - If operating on a directory recursively:
sudo chattr -R -i /path/to/directory - Retry the
chowncommand to verify ownership assignment succeeds.
Step 3: Check Filesystem Types and Mount Options (FAT32, NTFS, exFAT)
Non-Linux filesystems do not store POSIX ownership metadata; ownership is simulated globally at mount time.
- Determine the filesystem type of the partition hosting the target directory:
df -T /path/to/file - If the filesystem column indicates
vfat,exfat,ntfs, orcifs, individual filechowncommands are unsupported. - To assign ownership across an external drive or share, remount the filesystem specifying static
uidandgidmount options:sudo umount /mnt/drive sudo mount -t exfat -o uid=1000,gid=1000,umask=022 /dev/sdb1 /mnt/drive - Verify that your target user account now owns all contents within the mount point.
Step 4: Resolve NFS ‘Root Squash’ Restrictions
When executing chown across an NFS network share, the NFS server often squashes client root permissions to prevent unauthorized administrative escalation.
- Check if the target directory resides on an NFS network share:
mount | grep nfs - If the export configuration on the NFS server contains
root_squash(the default security policy), the server maps client root execution tonobody:nogroup, blockingchown. - To resolve this, either:
- Log in directly to the NFS storage server host and execute the
chowncommand locally. - Or update
/etc/exportson the NFS server to includeno_root_squashfor trusted client IP addresses, followed bysudo exportfs -ra.
- Log in directly to the NFS storage server host and execute the
Step 5: Verify Container Capabilities in Docker and Kubernetes
If running inside an unprivileged container or systemd jail, the kernel capability to modify ownership may be stripped.
- Check active kernel capabilities within your shell environment:
capsh --print - Look for
cap_chownin the Current capabilities list. - If
cap_chownis absent, the container runtime has dropped the capability. - In Docker, launch or configure the container with the capability explicitly granted:
docker run --cap-add=CHOWN ...
chown EPERM Error Diagnostic Summary
| Identified Cause | Diagnostic Command | Resolution Action |
|---|---|---|
| Non-root execution | id |
Execute command using sudo chown ... |
| Immutable file attribute | lsattr <file> shows i flag |
Execute sudo chattr -i <file> |
| Non-POSIX filesystem | df -T shows vfat, exfat, ntfs |
Mount with -o uid=1000,gid=1000 |
| NFS root squashing | mount | grep nfs |
Run chown directly on NFS server host |
| Missing container capability | capsh --print lacks cap_chown |
Add --cap-add=CHOWN to container flags |
Identifying the governing security layer ensures proper permission alignment, allowing chown to modify file and directory ownership successfully.