5

TL;DR: Why am I getting the Operation not permitted? And how can I resolve this?


I'm facing a problem which I can't resolve. I'm creating a directory as user a:group a), which I want to change to user b:group a. I don't understand why this operation is not permitted. This is what's happening:

user a@foo:~$ mkdir /home/user b/foo/test             
uber a@foo:~$ chmod 0777 /home/user b/foo/test
user a@foo:~$ ls -alF /home/user b/foo/ | grep test
drwxrwxrwx 2 user a            group a 4096 Jan  6 19:53 test/
user a@foo:~$ chown user b:group a /home/user b/foo/test
chown: changing ownership of `/home/user b/foo/test': Operation not permitted

(I changed the user and group names for simplicity's sake)

Other things that might be relevant:

  • User A is in Group A and Group B.
  • User B is in Group B.
  • Directory foo in /home/user b has 0750, and is owned to User B:Group A.

I'm eager to understand as why this operation is not permitted, and how I can resolve this (a solution without using sudo is a plus)?

2
  • try sudo before your chown command
    – kobaltz
    Jan 6, 2012 at 16:23
  • What are the permissions of the "foo" folder?
    – TheCompWiz
    Jan 6, 2012 at 16:29

2 Answers 2

15

You can only change ownership on a file if you're root (or have the CAP_CHOWN Posix capability). This is so because giving away files would trigger some security concerns (for example, if disks quotas were enabled you could then fill user b quota).

Use sudo chown if you're allowed to do so and it will work.

You can however change the owning group to a group you're a member of, so you should be able to chgrp "group b" "/home/user b/foo/test", which may be an alternative to share files with user b without becoming root, depending of what you're trying to achieve.

For more flexible permissions, you may want to look into ACLs.

3
  • Thanks for your explanation. For now, I went with sudo for a very small subset of commands. I'm going to look at chgrp.
    – Bjorn
    Jan 9, 2012 at 8:58
  • Nope, the following does not work for me: You can however change the owning group to a group you're a member of, so you should be able to chgrp "group b" "/home/user b/foo/test" -- the same "operation is not permitted" problem.
    – Ayrat
    Mar 29, 2016 at 13:36
  • Frustrating... I'm having the same problem as I see people like @Ayrat pointing out for years back, where the provided "answers" still give the same "operation is not permitted" problem, even with sudo, and never with any responses.
    – John Smith
    Nov 30, 2023 at 7:03
0

Part A:
The operation is not permitted because only the owner and root (TBOMK).

Part B: The answer is now obvious. Either have user b do it, or perhaps you will have to bite the bullet and use sudo. If you don't want to use sudo I assume it is because you don't have root and will have to get someone else to do it, but those appear to be the only two solutions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .