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)?

studiohack
  • 13,468
  • 19
  • 88
  • 118
Bjorn
  • 121
  • 1
  • 1
  • 6

2 Answers2

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.

gentledevil
  • 274
  • 1
  • 2
  • 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 09 '12 at 08: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 '16 at 13:36
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.

Yitzchak
  • 4,424
  • 6
  • 26
  • 44