LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   chown not working for changing owner (https://www.linuxquestions.org/questions/linux-newbie-8/chown-not-working-for-changing-owner-4175557871/)

arun natarajan 11-03-2015 09:21 AM

chown not working for changing owner
 
hi,

iam trying the change the ownership for a file from the user pooja to arun. but not able to achieve that , when am i executing the with pooja as current user. It is working if i execute the same with root as current user.

Solution, im looking for:
need to change the ownership of file aa and folder bb from pooja to arun, when pooja is the current user.


bash-3.2$ whoami
pooja

bash-3.2$ pwd
/home/pooja
bash-3.2$ ls
1 2 3 4 5 aa

bash-3.2$ chown arun aa
chown: changing ownership of `aa': Operation not permitted

bash-3.2$ chown user:arun aa
chown: `user:arun': invalid user

bash-3.2$ mkdir bb

bash-3.2$ chown -R user:arun bb
chown: `user:arun': invalid user

bash-3.2$ chown -c user:arun bb
chown: `user:arun': invalid user

bash-3.2$ chown -v arun bb
chown: changing ownership of `bb': Operation not permitted
failed to change ownership of `bb' to arun

bash-3.2$ chown -v arun a
chown: cannot access `a': No such file or directory
failed to change ownership of `a' to arun
bash-3.2$ chown -v arun aa

chown: changing ownership of `aa': Operation not permitted
failed to change ownership of `aa' to arun

bash-3.2$ chown arun: aa
chown: changing ownership of `aa': Operation not permitted

bash-3.2$ chown arun: bb
chown: changing ownership of `bb': Operation not permitted

Demosa 11-03-2015 09:28 AM

Simple. You cannot change ownership of a file without sudo permissions.

You can change file permissions with chmod, but you cannot change ownership without elevating permissions. It's a security and auditing feature.



EDIT: A few more details as to why. In the old days of UNIX/Linux, when users had a limited amount of space, changing the permissions to 777 and assigning the owner to someone else would let a user have more disk space at the expense of someone else's disk quota. A big deal when you pay by the megabyte for storage. By requiring sudo to change owners, this could be restricted

Soadyheid 11-03-2015 10:08 AM

Even though you own the file, you cannot change the ownership of it to that of someone else.

As you mention, root can do this so you either have to
Code:

$su root
(switch user to root) then issue the command, remembering to switch back to being a normal user afterwards or use sudo as Demosa mentions above.

Play Bonny!

:hattip:

Shadow_7 11-04-2015 11:00 AM

You can copy a file as a user (to your /home) and it inherits your creds. You can also delete files from your home that don't have your creds. Otherwise you need elevated permissions as hinted to by the error message.

rtmistler 11-04-2015 12:08 PM

Quote:

Originally Posted by Demosa (Post 5444081)
Simple. You cannot change ownership of a file without sudo permissions.

You can change file permissions with chmod, but you cannot change ownership without elevating permissions. It's a security and auditing feature.



EDIT: A few more details as to why. In the old days of UNIX/Linux, when users had a limited amount of space, changing the permissions to 777 and assigning the owner to someone else would let a user have more disk space at the expense of someone else's disk quota. A big deal when you pay by the megabyte for storage. By requiring sudo to change owners, this could be restricted

This I feel is the best suggestion. I do not recommend you fully become root, but instead utilize sudo.

A further point is to observe the group for the file. Many times each individual user has their own named group, typically matching their username. So consider "chgrp" as well.

I very regularly do use things like:
Code:

sudo chown -R new-name top-level-directory-name
sudo chgrp -R new-group-name top-level-directory-name



All times are GMT -5. The time now is 07:18 PM.