Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to create a shared directory when a number of users (all belong to say mygroup) can create and edit files. I would like all files in this directory and subdirectory to belong to mygroup

I have changed existing files to have group mygroup using chgrp, but new files still get created belong to the user's primary group. Is there a way of ensuring new files belong to the group without repeatedly running chgrp.

share|improve this question

2 Answers 2

up vote 24 down vote accepted

You want to set the SetGID sticky bit.

chmod g+s dir

All new files created in the directory will have the group set to the group of the directory.

A superuser blog post explained the sticky bits and other linux permission bits:

SetGID, however, is a whole different ball game. When a directory has the SetGID bit set and a file is created within that directory the group ownership of the file is automatically modified to be the group of the directory.

share|improve this answer
    
Thanks. The reference is useful. describes the umask command that is part of the picture –  justintime May 2 '11 at 17:43
    
What about creating a subdirectory in the initial directory which also belongs to the group of the parent directory? Is this possible? –  daaxix Mar 11 '13 at 22:27

Set the setgid permission flag on the folders.

chmod g+s dirname
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.