- The name of the shared directory: /home/projects
- The shared group name: developers
- Users: john, joe, and jane
First, log in as super user, create the projects directory.
$ mkdir /home/projects
Second, create a shared group.
$ groupadd developers
Set up directory for group sharing.
# Change group on the directory $ chgrp developers /home/projects # Set full permission for group on the directory $ chmod -R 775 /home/projects # Set SGID bit on the directory so that new files under this directory will inherit the directory's group instead of the user's (creator) group. $ chmod -R g+s /home/projects # OR combine the last two commands into one $ chmod -R 2775 /home/projects # Set umask on the directory so that the 'group write' permission will be inherited on new files and directories $ umask 002
Add users to group as supplementary group.
$ useradd -G developers john $ useradd -G developers joe $ useradd -G developers jane # Check their groups $ id john # Add a user to multiple supplementary groups (with no space after commas): $ useradd -G wheel,ftp,www,developers john # Add existing user to an existing group $ usermod -a -G wheel # Change user's primary group $ usermod -g developers john
You can also use this command to set the primary group for a user
$ useradd -g developers john