Why is the chown command root-only?
Why can't non-root users use chown to give away files they own?
|
|
||||
|
Most unix systems prevent users from “giving away” files, that is, users may only run The reason for this restriction is that giving away a file to another user can allow bad things to happen in uncommon, but still important situations. For example:
|
|||||||||
|
|
You can launch the command but it will not work if you are not root. It is easy : imagine a user which can change a software to root user. It can add the setuid bit and, voilà, the guy is root ! So, the use can add the bit with chmod, but no chance to change the owner of files. |
|||||
|
|
On Linux, you need the CAP_CHOWN capability to chown. root is granted such. Refer to: http://vouters.dyndns.org/tima/Linux-OpenVMS-C-Implementing_chown.html for explanations. If you intend to give the CAP_CHOWN capability, build your code with libcap-ng or libcap as demonstrated by: http://vouters.dyndns.org/tima/Linux-PAM-C-Pluggable_Authentication_Modules_programming_example.html where you have to simple replace CAP_AUDIT_WRITE with CAP_CHOWN. In the hope this can help you. |
|||
|
|
chownto give away files they own. (I've seen systems where, depending on the filesystem configuration, you can.) – Keith Thompson Dec 21 '11 at 21:49