How do you accomplish this?

You want to allow multiple users the write access to files within the same directory, in addition, you
want all the new files created in this directory to be of the required group instead of the primary ID
of the user who creates the file. How do you accomplish this?

You want to allow multiple users the write access to files within the same directory, in addition, you
want all the new files created in this directory to be of the required group instead of the primary ID
of the user who creates the file. How do you accomplish this?

A.
Set the setgid bit on the directory.

B.
Change the group owner of the new files manually.

C.
Run a cron job to change the group owner.

D.
Changethe primary group ID of every user to the required group.

Explanation:
Linux: SETGID on directory
SETGID stands for SET Group ID. We can use the command chmod to set the group ID bit for a
directory.
chmod g+s mydir
or with numeric mode:
chmod 2775 mydir
After the change, the permission of the directory “mydir” becomes “drwxrwsr-x”.
drwxrwsr-x 3 zen zen 4096 2010-03-18 19:57 mydir
But what is so special about setting the group ID for a directory? The trick is that when another
user creates a file or directory under such a directory “mydir”, the new file or directory will have its
group set as the group of the owner of “mydir”, instead of the group of the user who creates it.
For example, if user2 belongs to the groups “user2” (main group) and “zen”, and he creates a file
“newfile” under the diretory “mydir”, “newfile” will be owned by the group of “zen” instead of
user2’s main group ID “user2”.



Leave a Reply 0

Your email address will not be published. Required fields are marked *