Specify default group and permissions for new files in a certain directory

Posted by mislav on Server Fault See other posts from Server Fault or by mislav
Published on 2009-12-21T14:39:44Z Indexed on 2010/03/29 16:53 UTC
Read the original article Hit count: 326

Filed under:
|
|
|
|

I have a certain directory in which there is a project shared by multiple users. These users use SSH to gain access to this directory and modify/create files.

This project should only be writeable to a certain group of users: lets call it "mygroup". During an SSH session, all files/directories created by the current user should by default be owned by group "mygroup" and have group-writeable permissions.

I can solve the permissions problem with umask:

$ cd project
$ umask 002
$ touch test.txt

File "test.txt" is now group-writeable, but still belongs to my default group ("mislav", same as my username) and not to "mygroup". I can chgrp recursively to set the desired group, but I wanted to know is there a way to set some group implicitly like umask changes default permissions during a session.

This specific directory is a shared git repo with a working copy and I want git checkout and git reset operations to set the correct mask and group for new files created in the working copy. The OS is Ubuntu Linux.

Update: a colleague suggests I should look into getfacl/setfacl of POSIX ACL but the solution below combined with umask 002 in the current session is good enough for me and is much more simple.

© Server Fault or respective owner

Related posts about posix

Related posts about umask