# Primary group ID for newly created files



## bbk (Nov 6, 2013)

I want to give write access to a folder for many users, but the files and folder they create in it must have their primary group id. For example i create a directory as root and give the permissions for everyone:


```
root@hostname1:~ # mkdir /test
root@hostname1:~ # chmod 777 /test
root@hostname1:~ # ls -la /test
total 8
drwxrwxrwx   2 root  wheel   512 Nov  6 12:53 .
drwxr-xr-x  20 root  wheel  1024 Nov  6 12:53 ..
```
Now I create a file as user1 and user2:


```
$ id
uid=1002(user1) gid=1002(user1) groups=1002(user1)
$ touch /test/user1.txt
$ ls -la /test/user1.txt
-rw-r--r--  1 user1  wheel  0 Nov  6 13:01 /test/user1.txt
```


```
$ id
uid=1003(user2) gid=1003(user2) groups=1003(user2)
$ touch /test/user2.txt
$ ls -la /test/user2.txt 
-rw-r--r--  1 user2  wheel  0 Nov  6 13:03 /test/user2.txt
```
I want to have the following permissions:



> /test/user1.txt having the GID 1002
> /test/user2.txt having the GID 1003


Is it possible to configure the system that it creates new files and  folders with the primary group id of the user creating them?


----------



## kpa (Nov 6, 2013)

The primary groups look like they are set up correctly. That's not the issue however, the open(2) manual page states that:


```
When a new file is created it is given the group of the directory which
     contains it.
```

I'm not sure if there's any way to work around that.


----------



## bbk (Nov 6, 2013)

*NFSv3 solution?*

The user1 has the primary group user1 and is not in the group wheel, the same is valid for user2.

I was reading a lot that there are different behaviours and that this is the expected on FreeBSD, i was hoping there is a way around. However my aim is to provide a NFSv3 share with this behaviour, maybe there is a way around?


----------



## trh411 (Nov 6, 2013)

bbk said:
			
		

> I want to give write access to a folder for many users, but the files and folder they create in it *must have their primary group id*.



I'm curious, why *must* they? Help me understand your requirement.

Right now I'm thinking you would have to manipulate the files' group ownership after the fact, which would require a daemon process to monitor the directory in question.


----------



## bbk (Nov 6, 2013)

I have around 300 Linux clients and the users have the possibility to use an NFS share where they can create files and folders. The users are in various groups and have different umask settings and they can set the permission to give access to groups they belong to.

The current NFS share they use is based on Linux and the users are used to this behaviour, that's why I want to provide the same on the new NFS server.

A key point why I would like to use a FreeBSD server is the ZFS implementation, but I could also use http://zfsonlinux.org/ on Linux.

A daemon is not really possible (very complicated) as all users use the same folder but are in different groups.


----------



## Boyko (Jan 16, 2017)

I know this is an old thread but I'm facing the very same issue here.

Running latest Freebsd 11, zfs as root filesystem, there doesn't seem to be a way to switch from bsd-groups to sysv-groups style for group ownership. Directories behave as if they have the setgid flag set (chmod g+s or chmod 2770) while they don't. All newly created files inherit their group from the directory they reside in.

Looking for a way to change this so that newly created files get the primary group of the user who created them (sysv behavior - default on Linux). I checked the zfs dataset properties, mount options, kernel options, fs acls and chmod flags and couldn't find a way to switch this behavior.

Any ideas?


----------

