1

I tried to chown a file to root, that I own, But my machine says I'm not permitted. I've googled a bit and found a few topics that say chown is a root only command. But others say that's not true. Am I doing something wrong?

pi@raspberrypi /media/usb1 $ whoami
pi
pi@raspberrypi /media/usb1 $ ls -laxo
total 8
drwxr-x---  2 pi   4096 Jul 30 09:39 .
drwxr-xr-x 10 root 4096 Jul 29 12:52 ..
-rwxr-x---  1 pi      0 Jul 30 09:29 lol
pi@raspberrypi /media/usb1 $ chown root lol
chown: changing ownership of `lol': Operation not permitted

1 Answers1

5

Some older Unixes allowed to "give away" file ownership, but that has been abandoned long ago. In the days of true multiuser-boxes where hundreds of users connected through terminals to a unix machine, people learned to abuse this to get around their disk quotas. Moreover, giving away files is in some sense a form of social engineering, by which unwary users could be tricked into executing malicious programs. Thus, allowing chown for non-superusers bears more trouble than use and is therefore no longer provided.

So you need to be superuser to call chown.

But wait, there is more: If your system supports POSIX capabilities (as Linux does), then you don't need to be superuser, you just need to have the capability CAP_CHOWN.

countermode
  • 7,533
  • 5
  • 31
  • 58