Lucas Aimaretto
Lucas Aimaretto

Reputation: 1489

Subdirectory not created with proper group even parent has SGID

I have a folder with the SGID bit on:

lucas@arturito:/home$ ls -l | grep share
drwxrwsr-x 11 share      sambashare  4096 May  5 14:54 share

If I move into share an I create a folder within it, that folder will have the group 'sambashare'. So far, so good...

lucas@arturito:/home$ cd share/
lucas@arturito:/home/share$ mkdir test
lucas@arturito:/home/share$ ls -l | grep test
drwxrwsr-x  2 lucas sambashare 4096 May  5 15:07 test

Now, if I move under /home/share/test and create a new folder, that new folder inherits the group: SGID is working.

lucas@arturito:/home/share$ cd test
lucas@arturito:/home/share/test$ mkdir test1
lucas@arturito:/home/share/test$ ls -l | grep test1
drwxrwsr-x 2 lucas sambashare 4096 May  5 15:09 test1

However, under /home/share I do have other folders other than the newly created 'test'. If I move under any of those, and create a new folder (say 'test2'), that new folder will ignore the SGID and the group will be my group.

lucas@arturito:/home/share$ ls -l | grep 99
drwxrwxr-x  9 share sambashare 4096 May  5 15:11 99_varios

lucas@arturito:/home/share$ cd 99_varios/
lucas@arturito:/home/share/99_varios$ mkdir test2
lucas@arturito:/home/share/99_varios$ ls -l | grep test2
drwxrwxr-x  2 lucas lucas      4096 May  5 15:11 test2

Why is that happening? Isn't it enough for /home/share to have g+s for any other directory below it (new or old) to inherit /home/share's group?

I'm lost. Any hint or idea will be highly appreciated!

Thanks!

Lucas

Upvotes: 0

Views: 394

Answers (1)

Alfred Rossi
Alfred Rossi

Reputation: 1986

New folders will inherit the bit but existing ones need to have it set explicitly. You can run the command below once to recursively set it on any existing subfolders.

find /home/share -type d -exec chmod g+s '{}' \;

Upvotes: 2

Related Questions