Issue
Here is the setup:
- I have a user called
git
with aumask
of022
. git
adds files and folders into a folder calledhtdocs
.htdocs
hasdrwxr-srx
permissions (gid set) and is owned bygit:apache
- Created files and folders in
htdocs
have-rw-r--r--
(644) anddrwxr-srx
(2775)
Sometimes I need to give Apache write permissions to a folder:
chmod g+w some-folder
The problem is that it loses the gid, so instead of:
drwxrwsr-x
I get:
drwxrwxr-x
When I try to add the gid back:
chmod g+s some-folder
It doesn't do anything. some-folder
still only has 755 permissions.
I also tried manually setting it to 2755:
chmod 2755 some-folder
With no luck.
Does anyone have any thoughts on how I can keep the gid set?
Update
After a few additional hours of research and seeing that other users had the same issue, @twalberg nailed the only two options available. I decided to create a new group and place both git and apache in it. Now that git belongs to that group, the gid remains set.
Solution
man 2 chmod
has this to say:
If the calling process is not privileged (Linux: does not have the
CAP_FSETID capability), and the group of the file does not match the
effective group ID of the process or one of its supplementary group
IDs, the S_ISGID bit will be turned off, but this will not cause an
error to be returned.
I am guessing that git
is not in the apache
group, so when git
changes the mode on the directory, the setgid bit is automatically cleared. You can either add git
to the apache
group, or use a privileged account to do the chmod
.
Answered By - twalberg Answer Checked By - Senaida (WPSolving Volunteer)