I'm using Linux Mint 18.Let's say there're several shared directories.Each directory belongs to a specific group.One of this is foo and must be shared by Pippo and Pluto so I've created the group foo and I've added Pippo and Pluto to it.All contents created inside foo and its subdirectories must be accessible to both Pippo and Pluto regardless the creator is Pippo or Pluto. The problem is that when creating a new file or directory the id group of the content is set to Pluto or Pippo(depending by whom the content has been created)and not to foo even if I've changed the group of the foo folder and its subdirectories and files to foo.

What's the way to give to new contents the group foo?


Outside the foo folder every file created by Pippo or Pluto must have the group set respectively to Pippo and Pluto.


The default behaviour (as you have found out) is to give a file the same UID and GID as the owner. If you want to override that, you need to set the setgid bit on the directory that stores the file. This will not affect already-existing files and directories, so you'll need to fix the permissions on each directory underneath as well (as @cas mentioned, you probably want to allow the members of the foo group to modify each others' work (and view the directories), so you'll want to add those permissions too.)

To fix this (assuming you've already created the directory structure), run the following from the root of the structure:

find . -type d -exec chmod g=rwsX {} \;
chgrp -R foo *

I used find to select just the directories, as setting the setuid/setgid bits on files has a different meaning. Of course, if you're creating a new directory, you just have to run the chmod/chgrp commands without using find.

EDIT: Fixed the chmod permissions.

| improve this answer | |
  • that chmod should be g+s, not u+s. and you should make sure the directories are read, write, and executable by group members too. so chmod g=rwsX – cas Jan 25 '18 at 11:17
  • could you explain the meaning of both {} and \?Thanks – Antonio Del Sannio Jan 25 '18 at 11:25
  • OK {} tells find to use the found name with chmod and \ remove the path from the file name?Is it right? – Antonio Del Sannio Jan 25 '18 at 11:31
  • The man page for find(1) (under -exec) has the details. {} is a placeholder for the matched file, and ; ends the command line. As the shell treats ; specially, you need to escape it (so it becomes \;). – ErikF Jan 25 '18 at 11:35
  • i'm sorry I didn't see there is not space between \ and ; now it's clear – Antonio Del Sannio Jan 25 '18 at 11:43

You could run a cron job to recursively change the contents owners to the foo group.

| improve this answer | |
  • Yes ,but i was thinking a better way should exist,something related to the id number ,but i lack of knowledge about this. – Antonio Del Sannio Jan 25 '18 at 10:57
  • Right. I think this is a better solution. – Jaken551 Jan 25 '18 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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