Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
    
try sudo before your chown command –  kobaltz Jan 6 '12 at 16:23
    
What are the permissions of the "foo" folder? –  TheCompWiz Jan 6 '12 at 16:29

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
    
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 '12 at 8:58

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.