Subject: Re: bug#5826: [feature] chmod +S to setgid directories alike +X

From: Bob Proulx <[email-masked]>
Date: Sat, 3 Apr 2010 13:57:59 -0600

Michał Górny wrote:
> I would really appreciate if chmod supported setting setgid permissions
> on directories (and files already having such) recursively, much like
> '+X' does set executable permission. To match the '+X' one, I suggest
> using '+S' for that.

I suggest using 'find' for this.  And there is an advantage to using a
standard command.  It works anywhere.

  $ find . -type d -exec chmod g+s {} +

Also the setgid bit isn't like the execute bit.  They can't be directly
compared.  There are three execute bits.  The +X implements a not
completely trivial control flow.  If the file is a directory OR if the
file already had the user execute bit or the group execute bit or the
other execute bit set.  It is the three execute bits that makes it
non-trivial and the usefulness of the +X mode.  But by contrast
setting the setgid bit is very simple.  Just set it.  It is only one
bit.

Plus there are security ramifications to think about when setting the
setgid bit on files.  And the decisions are operating system
dependent.  On most systems scripts should never be suid/sgid.  And
even on systems where it is safe to do so I don't think setting the
suid/sgid bit on normal executables is something that should be done
lightly.

Bob