USERS, GROUPS AND DIRECTORIES ON LINUX
Step-by-step guide to create users and groups, and then add those users to their respective groups and create a directory for each group in Linux:
Creating Groups
You need to be a privelege user mode to execute these commande
To create a new group, use the `groupadd` command. In this example, we will create 3 groups( Developpers, Engineers and Administrators)
sudo groupadd Developers
Type the same command with the appropriate group’s name and then hit enter for the rest of the groups.
sudo groupadd Engineers
sudo groupadd Administrators
2. Verify the groups were created by checking the ‘etc/group’ file:
grep ‘Developers\|Engineers\|Administrators’ /etc/group
Creating Users in a spefic group
- To create a new user and add them to a specific group, use the `useradd` command with the `-g` option for the primary group ( e.g, Jerry, Tom and Bob).
sudo useradd -g Developers Jerry
sudo useradd -g Engineers Tom
sudo useradd -g Administrators Bob
2. Set passwords for the new users:
sudo passwd Jerry
sudo passwd Tom
sudo passwd Bob
3. Verify the group memberships with the `id` command:
id Jerry
id Tom
id Bob
Creating Group Directories
- Create a directory for each group and set the appropriate group ownership:
Directories ( make sure you’re in the home directory)
Get Azizou GNANKPE’s stories in your inbox
Join Medium for free to get updates from this writer.
sudo mkdir {Developers,Engineers,Administrators}
Ownership ( make sure you’re in the home directory)
sudo chgrp Developers Developers
sudo chgrp Engineers Engineers
sudo chgrp Administrators Administrators
Type ls -ls command to see each directory’s group belonging
The `chmod g+s` command sets the “setgid” bit on a directory in Unix-like systems, including Linux. When the setgid bit is enabled on a directory
New subdirectories created within that directory inherit the group ownership of the parent directory instead of the user’s primary group.
New files and directories created within that directory inherit the group permissions of the parent directory, ensuring consistent group access.
sudo chmod g+s Developers
sudo chmod g+s Engineers
sudo chmod g+s Administrators
Set the sticky bit on each directory, with the ‘chmod o+t path/to/directory’ command. The sticky bit is commonly used on world-writable directories like /tmp to allow anyone to create files there, but prevent deletion of files by anyone other than the file owner or root.
sudo chmod o+t /home/Developers
sudo chmod o+t /home/Engineers
sudo chmod o+t /home/Administrators
Type the ‘ls -l’ command to see how all your directories will change in color. Protection and inheritance have been enabled on them all.
2. Set the permissions for the group directories to allow read/write access for group members:
sudo chmod 770 /home/Developers
sudo chmod 770 /home/Engineers
sudo chmod 770 /home/Administrators
Now you have created the groups (Developesr, Engineers, Administrators), users (Jerry, Tom, Bob) with their respective primary groups and created a directory for each group with the proper permissions for group members to read and write files.
Congrats!!









