Why can't user1 change ownership (chown) of a file to user2?

rstoeck
rstoeck used Ask the Experts™
on
I'm a novice on Linux so I suspect this is an easy question. :-)

I'm trying to change ownership of a file to another user, but am getting an "Operation not permitted" error.

In the following example, user "rob" runs chown on a file named "foobar", which is owned by "rob". Shouldn't the current owner of the file be able to change the owner to someone else? In this example, the desired new owner is user "www-data".

rob@mc-web1:/data01/home/rob/test$ ls -l
-rw-r----- 1 rob rob 9 Jan 28 10:07 foobar

rob@mc-web1:/data01/home/rob/test$ chown www-data foobar
chown: changing ownership of `foobar': Operation not permitted

What am I missing?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2013
Top Expert 2013
Commented:
Hi,
only root can do this.
The changed file, if executable, would run under the new account, which possibly has more privileges than the original user.
This is a security risk, thus the restriction.
wmp
 

Author

Commented:
Thanks.

My "Linux In A Nutshell" book says in regards to chown: "Only the current owner of a file or a privileged user may change its owner". Guess that is not right.

It appears that only a privileged user may change a file's ownership.
Most Valuable Expert 2013
Top Expert 2013

Commented:
Well,
 "Only the current owner of a file or a privileged user may change its owner".
thats incorrect for every Unix/Linux I'm aware of.
Here is more info -  http://www.gnu.org/software/coreutils/faq/#Why-can-only-root-chown-files_003f
Thx for the points!
wmp
Most Valuable Expert 2013
Top Expert 2013

Commented:
So even O'Reilly is publishing nonsense sometime ...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial