Linux – Using chown to change the group owner of a directory is not permitted….Why

chmodchownlinuxpermissions

I am trying to execute chown on a directory that has the following permissions and owners:

drwxrwxr-x 2 justin devs  4096 Jan  1 20:42 test

I am trying to simply execute the following as the justin user:

chown justin:nginx test

So basically just change the group owner to nginx, but I am getting:

chown: changing ownership of `test/': Operation not permitted

Any ideas?

Best Answer

First, use the chgrp command instead of chown and that will work.

In the case of using chown, for security reasons in most Linux contexts, any ownership change is restricted to the root user even though you are marked as the owner of the file, directory, etc or not. In one case, this is to prevent users from evading quotas by setting the file permission bits to 777 and changing the ownership of a file to some other unknown user and eating up their quota.

So using the chown command in a user context, especially where the ownership is not changing should not be used just to change the group of a file.

NOTE: You must be a member of the group you are attempting to change the file to. This can be verified by id -a. If you are not in the group, you will get this message eventhough you are the owner of the file.