chown “operation not permitted” error – possible solutions

On Linux or Unix-bases system, chown is the command that allows you to change the user/group ownership of a given path. The path can lead to a file, a directory, or symbolic link.

In this article, we will show you a few solutions to "Operation not permitted" error when running chown commands, as well as how filesystem security policy works in Linux so you can avoid running into this error later.

File permissions in Linux

Native Linux filesystem (EXT) uses file permissions and file ownership to control who gets to do what with files. There are three types of file permissions:

  • Owner refer to the person or process who created the file. These type of file permission affect the owner of the file.
  • Group refers to a group of users that share the same set of permissions.
  • Other are all the users who are neither the owner, nor a member of the group.

"Operation not permitted" common causes

Once you got an overview of how permissions work in Linux, you may see that "Operation not permitted" often caused by one of the following reasons:

  • The filesystem is not Linux-native (EXT, EXT2, EXT3, EXT4, JFS, Minix, ReiserFS, Reiser4, XFS)
  • The file has the immutable flag set in its extended attributes
  • No root provileges. You need to be root to change the ownership of a file.
  • Storage device mounted with insufficient options.
  • Storage device mounted read-only.
  • SELinux or other security enforcers applied, prevent certain users to perform certain actions on the filesystem.

Extended attributes

This is by far the most common cause of the "chown operation not permitted" error message. In this situation, the file has the immutable flag set in its extended attributes. In the example below, we create a file with the immutable flag set using chattr +i, named the_file and tries to chown it only to see "chown operation not permitted" error message.

In order to verify if this is exactly the problematic attribute,

user@LinuxPip ~/tmp % touch the_file [email protected] ~/tmp % sudo chown root:root the_file [sudo] password for user: [email protected] ~/tmp % sudo chattr +i the_file [email protected] ~/tmp % lsattr the_file ----i--------e-- the_file [email protected] ~/tmp % sudo chown user:user the_file chown: changing ownership of 'immutable': Operation not permitted
Code language: CSS (css)

In order to remove immutable attribute, run sudo chattr -i filename (the -i stands for minus immutable)

user@LinuxPip ~/tmp % sudo chattr -i immutable [email protected] ~/tmp % lsattr the_file -------------e-- the_file [email protected] ~/tmp % sudo chown user:user the_file [email protected] ~/tmp %
Code language: CSS (css)

Insufficient options

Sometimes, permissions on a single file is determined by the mount options of the whole partition (which in turn, means you cannot change it via chmod).

In this case, to inspect the current mounted volumes, run the following command :

[email protected]:~$ grep '/dev' /proc/mounts
Code language: JavaScript (javascript)

Or simpler, you can re-mount the volume with '755' on files and '777' on directories, you can use something like below. Remember to replace whatever in the command with details suitable to your system.

sudo mount -t ntfs -o rw,auto,user,fmask=0022,dmask=0000 /dev/whatever /mnt/whatever

Wrong filesystem

Contrary to what most people believe, NTFS is a POSIX-compatible¹ filesystem, and it is possible to use permissions on NTFS.

If you're performing operations on a NTFS formatted system, you should know that NTFS is also a POSIX-compatible filesystem. That means it is possible to use permissions on NTFS.

In order to enable permissions settings, you need a "User Mapping File" or mount the volume with permissions option in the first place. This maps between identities in Windows and Linux and write/read files with the correct user IDs like NTFS/Windows use them internally.

The ntfs-3g manpage provides some useful info and examples on this. If you need more information, see the ntfs-3g advanced documentation about ownership and permissions.

No root privileges

In Linux, you have to be root or have root privileges to change the owner of files/directories. In order to run commands under root privileges, prefix it with sudo. Alternatively, in case you've just ran it, run sudo !! to run the last command without typing it again.

We hope that the information above helped you solve chown operation not permitted error message. You may be interested in our Linux software roundups, including 8 Best Open Source CMDB softwareBest Linux Video ConvertersBest Linux Home Security Software, or best SNES emulator for Linux.

If you have any suggestion, please feel free to leave a comment below.

Click to rate this post!
[Total: 0 Average: 0]

Leave a Comment