terrytheandroid
Posts: 15
Joined: Thu Jan 10, 2013 1:38 am

chmod Problem

Wed Jan 16, 2013 4:15 pm

I've been playing with chmod and have hit a problem. I can set the userid bit on a directory but it won't un-set. See below.

Code: Select all

[email protected] ~ $ umask
0022
[email protected] ~ $ mkdir freddy
[email protected] ~ $ ls -ld freddy
drwxr-xr-x 2 pi pi 4096 Jan 16 16:10 freddy
[email protected] ~ $ chmod 2775 freddy
[email protected] ~ $ ls -ld freddy
drwxrwsr-x 2 pi pi 4096 Jan 16 16:10 freddy
[email protected] ~ $ chmod 0755 freddy
[email protected] ~ $ ls -ld freddy
drwxr-sr-x 2 pi pi 4096 Jan 16 16:10 freddy
[email protected] ~ $
This works fine on other *nix systems. ANy ideas?

Thanks

User avatar
bgreat
Posts: 235
Joined: Mon Jan 23, 2012 2:09 pm

Re: chmod Problem

Wed Jan 16, 2013 4:30 pm

Use the following for changing the directory usrid bit:

Code: Select all

[email protected] ~ $ mkdir freddy
[email protected] ~ $ ls -ld freddy
drwxr-xr-x 2 pi pi 4096 Jan 16 11:27 freddy
[email protected] ~ $ chmod +s,g+w freddy
[email protected] ~ $ ls -ld freddy
drwsrwsr-x 2 pi pi 4096 Jan 16 11:27 freddy
[email protected] ~ $ chmod -s freddy
[email protected] ~ $ ls -ld freddy
drwxrwxr-x 2 pi pi 4096 Jan 16 11:27 freddy
To avoid issues with possible differing implementations of the extended mode bits, I prefer using the letter representation when setting permissions. See 'man chmod' for more information.

Enjoy!
Bill

User avatar
jojopi
Posts: 3141
Joined: Tue Oct 11, 2011 8:38 pm

Re: chmod Problem

Wed Jan 16, 2013 4:31 pm

This is explained in the man page:
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.
And that is allowed by POSIX, because requests to set or clear the set-id bits on non-regular files are implementation-defined.

On Linux the set-group-ID bit on a directory causes files and subdirectories to inherit the group ownership. So it is good that you do not lose this behaviour by accident when you only meant to change the permissions.

terrytheandroid
Posts: 15
Joined: Thu Jan 10, 2013 1:38 am

Re: chmod Problem

Wed Jan 16, 2013 5:19 pm

Brill. Thanks Both. A feature, not a fault :)

chmod -t works fine too

Return to “Advanced users”