Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

up vote 8 down vote accepted

In order to have all files under a given directory inherit group rights, you need to use the setgid bit on your directory. See this link.

 $ mkdir test
 $ sudo chown raphink.staff test
 $ ls -lhd test
     drwxr-xr-x 2 raphink staff 4.0K 2009-12-21 16:19 test
 $ sudo chmod g+s test # Set the setgid bit
 $ ls -lhd test
     drwxr-sr-x 2 raphink staff 4.0K 2009-12-21 16:21 test
 $ touch test/foo
 $ ls -lh test
     total 0
     -rw-r--r-- 1 raphink staff 0 2009-12-21 16:23 foo
share|improve this answer
    
Thanks. Interesting that I didn't find this by googling –  mislav Dec 21 '09 at 22:13

I'm not much of an expert when it comes to the *nix side, but I think what you're looking for is called setgid.

See here.

share|improve this answer

It is difficult to inherit parent directory permissions in Linux/UNIX without using ACLs. but there is a way to assign default file permissions, check bellow link

Can you inherit parent directory permissions.

share|improve this answer

If you want to do this with an existing folder, you need to make sure the setgid bit is enabled for all subfolders as well. However, you don't need it on files, and you probably don't want it on files either. Here is how to set it for all subfolders recursively.

find /path/to/base/dir -type d -exec chmod g+s {} +
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.