Score:0

Different behavior of SGID in *BSD and Linux

mo flag

I came across an interesting thing: on BSD systems a new file will have group set to the group of the directory. On System V systems it will have the primary group of the user that created the file. As for BSD systems, what is the purpose of such behavior and does it mean that SGID bit is useless there?

Score:0
nc flag

This may or may not be an OS dependent feature, you haven't given enough details to tell.

The sgid bit on an executable causes it to run in the file's group even if the user running it isn't in that group. (set group id) If it's not executable, the sgid bit is mostly moot.

On a directory, the sgid bit has been repurposed to control group inheritance within the directory. If the sgid bit is set on a directory, files created in the directory inherit the group (but not the group permissions). The point of this is that if you have a shared directory used by users in a group, they can all set their umask to 002 instead of 022 and all edit the files in the directory without needing to constantly fix group permissions. (Without the umask change, this is less useful.)

So possibly on the two systems you were looking at, one had the sgid bit set on the directory you were testing in, and one did not. This feature hasn't been around forever, so if one of the systems is sufficiently old, it may not support sgid directory inheritance. (But it has been around almost forever, so this is unlikely.)

This in no way makes sgid useless, I'm not sure why you would think that, you didn't explain what you think is useless. Note that if a file has a group owner for a group you are not in, you won't be able to make the file sgid without changing the group owner first, and if a non-root user copies the file, sgid is dropped.

Dima avatar
mo flag
I am sorry for being too short in my question. Thank you greatly for your reply. What made me ask this here was a migration from TrueNAS SCALE to TrueNAS Core. I find TrueNAS SCALE pretty raw thus I decided to migrate. During the process I discovered that some of my shares are no longer valid and I cannot use them nor offer them to users. Investigation showed that it was all about weird permissions on a new filesystem objects and then I discovered that behavior of FreeBSD 13 which is a core of TrueNAS 13.
user10489 avatar
nc flag
All unix based systems have worked this way for a very long time. Possibly the target directly had sgid set and all the subdirectories inherited it when you copied.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.