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 |
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 |
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 Play Bonny! :hattip: |
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.
|
Quote:
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 |
All times are GMT -5. The time now is 07:18 PM. |