Suppose that we want to create a folder in which multiple users will have full access (which means that they will be able to read, write, and execute).
- We create the folder (under ‘/’ in this example, although it can be anywhere else):
sudo mkdir test
which has the following permissions:
drwxr-xr-x 2 root root 4096 Oct 23 13:07 test
- We make a new group of users (“testers”):
sudo groupadd testers
and then we add to this group all users we want to have access:
sudo usermod -a -G testers testuser
(id testuser will return the groups that the testuser belongs to)
- We change the permissions of the shared folder (this is more useful if we have copied or moved a folder with some contents already):
sudo chgrp -R testers /test
sudo chmod -R g+rwx /test
so as every user in the groups “testers” can access the folder.
However, when a user creates a file, it is assigned with the permissions set by the user and its primary group, e.g.-rw-rw-r-- 1 testuser testuser 0 Oct 23 14:21 tempfile
- In order to automatically assign the permissions of the group when creating files and folders in the shared folder, we assign the “s” option (for setting the group id – SGID):
chmod -R g+s test
For example:
drwxrwsr-x 2 testuser testers 4096 Oct 23 14:34 newdir
-rw-rw-r-- 1 testuser testers 0 Oct 23 14:35 newfile
Now everyone in the “testers” groups can create, edit, delete, etc. the contents of this folder.
Useful articles:
[1] “How can I give write-access of a folder to all users in linux?”, Superuser.com, retrieved on Oct 23, 2014
[2] “Using SGID to Control Group Ownership of Directories”, Yale University Library Workstation Support / Yale University Library, retrieved Oct 23, 2014
[3] “Linux chmod command sticky bit example and implementations”, ComputerNetworkingNotes.com, retrieved Oct 23, 2014