Sample Header Ad - 728x90

Why does chown reset/remove the SUID bit and reset capabilities?

3 votes
1 answer
851 views
This command:
sudo chown -R root:root directory
will remove the SUID bit and reset all capabilities for *files*. I wonder why it's done silently and it's not mentioned in the man page. Weirdly the GUID bit is not removed. And it doesn't matter who the file or directory belonged to prior to running this command. Also SUID/GUID bits are *not* removed for *directories* (thought they are useless in this case). Presumably it's done in the name of security but to me it must not be done silently. This gets even worse:
$ setcap cap_sys_rawio,cap_sys_nice=+ep test
$ getcap -v test 
test cap_sys_rawio,cap_sys_nice=ep

$ chown -c -v -R 0:0 .
ownership of './test' retained as root:root
ownership of '.' retained as root:root

$  getcap -v test 
test
The SUID bit for the test file is removed completely silently. It's as if the command is doing a lot more than requested.
Asked by Artem S. Tashkinov (32730 rep)
Mar 14, 2024, 01:05 PM
Last activity: Mar 14, 2024, 03:11 PM