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

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 via chattr.
  • 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 nobody account.
  • Dropped Linux Capabilities in Containers: Docker or LXC containers running without the CAP_CHOWN capability 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.

  1. If you executed chown as a normal user:
    chown user:group filename
  2. 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).
  3. Prefix the command with sudo to invoke superuser privileges:
    sudo chown user:group filename
  4. 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.

  1. Inspect the extended attributes of the target file using lsattr:
    lsattr /path/to/file
  2. 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.
  3. Remove the immutable flag using chattr -i with root privileges:
    sudo chattr -i /path/to/file
  4. If operating on a directory recursively:
    sudo chattr -R -i /path/to/directory
  5. Retry the chown command 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.

  1. Determine the filesystem type of the partition hosting the target directory:
    df -T /path/to/file
  2. If the filesystem column indicates vfat, exfat, ntfs, or cifs, individual file chown commands are unsupported.
  3. To assign ownership across an external drive or share, remount the filesystem specifying static uid and gid mount options:
    sudo umount /mnt/drive
    sudo mount -t exfat -o uid=1000,gid=1000,umask=022 /dev/sdb1 /mnt/drive
  4. 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.

  1. Check if the target directory resides on an NFS network share:
    mount | grep nfs
  2. If the export configuration on the NFS server contains root_squash (the default security policy), the server maps client root execution to nobody:nogroup, blocking chown.
  3. To resolve this, either:
    • Log in directly to the NFS storage server host and execute the chown command locally.
    • Or update /etc/exports on the NFS server to include no_root_squash for trusted client IP addresses, followed by sudo exportfs -ra.

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.

  1. Check active kernel capabilities within your shell environment:
    capsh --print
  2. Look for cap_chown in the Current capabilities list.
  3. If cap_chown is absent, the container runtime has dropped the capability.
  4. 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.

Get the best tech tips delivered straight to your inbox.

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