Răspuns: chmod behaviour

Jonathan S Billings jsbillin at umich.edu
Fri Nov 4 12:29:56 UTC 2011


On 11/04/2011 03:27 AM, RuceLee wrote:
> [root at core2duo ~]# chmod 0755 my_directory/ #set perm in octal mode
> [root at core2duo ~]# ll -d my_directory/ #no effect on SGIT bit
> drwxr-sr-x 2 root root 4096 Nov  4 08:16 my_directory/
>
> [root at core2duo ~]# chmod g-s my_directory/ #set perm in symbolic mode
> [root at core2duo ~]# ll -d my_directory/ #get back to the execution bit
> drwxr-xr-x 2 root root 4096 Nov  4 08:16 my_directory/
>
> I'm confused cuz up until now I assumed the octal and symbolic mode
> are interchangeable and here is an example where I rather have to use a
> single mode to get to expected result.

The documentation from coreutils:
https://www.gnu.org/s/coreutils/manual/html_node/Directory-Setuid-and-Setgid.html#Directory-Setuid-and-Setgid

Basically, you can't use the numeric modes to clear a directory's 
set-user-id and set-group-id bits.  You have to use the symbolic mode to 
clear them.

The RHEL6 man page for 'chmod' actually mentions this in the "SETUID AND 
SETGID BITS" section:

        chmod preserves  a  directory’s  set-user-ID  and
        set-group-ID  bits  unless you explicitly specify
        otherwise.  You can set or clear  the  bits  with
        symbolic  modes like u+s and g-s, and you can set
        (but not clear) the bits with a numeric mode.


-- 
Jonathan Billings <jsbillin at umich.edu>
College of Engineering - CAEN - Unix and Linux Support




More information about the redhat-list mailing list