How to Fix ‘chown: changing ownership of: Operation not permitted’ in Linux

Executing the chown command in Linux to transfer file or directory ownership to a different user or group is a standard administrative task. However, receiving the error: ‘chown: changing ownership of ‘/path/to/file’: Operation not permitted’ halts shell automation and system administration workflows. Crucially, this error frequently occurs even when the command is executed with sudo or directly by the root superuser. In Linux, ownership changes require the kernel capability CAP_CHOWN, and operations will be blocked whenever underlying filesystem attributes, network mounts, or mandatory access controls restrict ownership modification.

Why Does chown Fail with ‘Operation Not Permitted’?

Standard Linux POSIX security specifies that only the superuser (or processes possessing CAP_CHOWN) may change a file’s owner. Even for root, several mechanisms can prevent ownership updates:

  • Immutable or Append-Only Filesystem Attributes: The file or directory has the +i (immutable) or +a (append-only) attribute set via chattr, preventing any metadata modification.
  • Network Filesystem (NFS) Root Squashing: Remote NFS shares mounted with root_squash map the local root user to an unprivileged account (such as nobody), denying ownership alterations on the server.
  • FAT32, exFAT, or NTFS Mounts: Non-POSIX filesystems lack native Linux user/group ownership fields. File ownership is statically assigned at mount time and cannot be altered using chown.
  • Read-Only Mount Options: The filesystem is mounted as read-only (ro) due to storage health degradation or manual mount flags.
  • Rootless Container User Namespaces: Running inside Docker or Podman where the container’s virtual root is mapped to an unprivileged UID on the host kernel.

Step 1: Check and Remove Immutable Attributes

Extended attributes can lock files completely against deletion, renaming, or ownership changes.

  1. Check the file’s extended attributes using lsattr:
    lsattr /path/to/file
  2. If the output displays the letter i (immutable) or a (append-only), remove it using chattr with superuser privileges:
    sudo chattr -i /path/to/file
  3. If you are changing ownership of an entire directory tree recursively, remove immutable attributes across the hierarchy:
    sudo chattr -R -i /path/to/directory
  4. Re-run the chown command:
    sudo chown username:groupname /path/to/file

Step 2: Inspect Mount Type and Read-Only Status

Determine whether the file resides on a non-Linux filesystem or a read-only partition.

  1. Find the filesystem mount details for the target directory:
    df -T /path/to/file
  2. Inspect the mount flags in the kernel table:
    mount | grep $(df -P /path/to/file | awk 'NR==2 {print $1}')
  3. If the filesystem is mounted as ro (read-only), remount it in read-write mode:
    sudo mount -o remount,rw /mount/point
  4. If the filesystem type is vfat, exfat, or ntfs, chown will always fail with Operation not permitted. To change ownership on these drives, remount the disk in /etc/fstab specifying the desired UID and GID:
    UUID=xxxx-xxxx /mnt/storage ntfs-3g uid=1000,gid=1000,umask=022 0 0

Step 3: Address NFS Root Squashing

If the directory is mounted over Network File System (NFS), server-side security policies frequently neutralise root privileges.

  1. Check if the mount point is an NFS share:
    mount -t nfs,nfs4
  2. On the remote NFS server, check the export configuration in /etc/exports.
  3. If the export line uses root_squash (the secure default), change ownership directly on the NFS server rather than from the client workstation:
    # On the NFS server directly:
    sudo chown username:groupname /exported/directory/file
  4. Alternatively, if appropriate for trusted private networks, configure no_root_squash on the server’s /etc/exports file and reload the export table with sudo exportfs -ra.

Step 4: Verify User and Group Existence

Specifying a non-existent UID, user account name, or group identifier triggers syntax or resolution errors.

  1. Verify that the destination user exists in the local user database:
    id username
  2. Verify the group exists:
    getent group groupname
  3. Execute chown specifying valid user and group parameters:
    sudo chown user:group filename

Step 5: Check Security Modules (SELinux and AppArmor)

Mandatory Access Control (MAC) systems can intercept and deny ownership updates even for root.

  1. On RHEL, Rocky Linux, or Fedora systems, check SELinux denial logs:
    sudo ausearch -m avc -ts recent
  2. If an SELinux security context prevents modifications, restore default file contexts:
    sudo restorecon -Rv /path/to/directory

Clearing immutable attributes with chattr, identifying non-POSIX filesystems, and accounting for NFS root squashing ensures ownership updates execute smoothly across Linux environments.

Get the best tech tips delivered straight to your inbox.

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