Introduction
User and group management is a fundamental aspect of Linux system administration. By organizing users into groups, system administrators can efficiently manage file permissions, access controls, and resource sharing across multiple users.
In this lab, you will learn how to create groups in Linux and add users to these groups. These skills are essential for managing collaborative environments where multiple team members need access to the same resources. You will create a group for a VR design team and add users to it, allowing them to share access to project files and resources.
Through hands-on practice with commands like groupadd and usermod, you will gain practical experience in Linux user management that can be applied to real-world system administration tasks.
Creating a New Group
In Linux, groups are used to organize users and manage permissions collectively. By adding users to a specific group, you can grant permissions to all group members at once instead of configuring them individually. This is particularly useful in collaborative environments where multiple users need access to the same resources.
In this step, you will create a new group named vr_designers using the groupadd command. This command is specifically designed for creating new groups in Linux.
First, make sure you are in the project directory. Open a terminal and navigate to the project directory with the following command:
cd ~/project
Now, create the new group by executing the following command:
sudo groupadd vr_designers
Let's break down this command:
sudo: This elevates your privileges temporarily to perform administrative tasksgroupadd: The command used to create a new groupvr_designers: The name of the group you are creating
After executing this command, you should see no output, which is normal for many Linux commands that complete successfully.
To verify that the group was created successfully, you can check the /etc/group file, which contains information about all groups on the system. Use the grep command to filter and display only the line related to your new group:
grep "vr_designers" /etc/group
You should see output similar to:
vr_designers:x:1001:
This output shows:
vr_designers: The name of the groupx: A placeholder for the group password (rarely used in modern systems)1001: The Group ID (GID) assigned to the group- The final colon would be followed by a comma-separated list of users in the group (currently empty)
Congratulations! You have successfully created a new group in Linux.
Adding Users to the Group
Now that you have created the vr_designers group, the next step is to add users to this group. When users are added to a group, they inherit all the permissions and access rights assigned to that group.
In this step, you will add three users—user1, user2, and user3—to the vr_designers group using the usermod command. These users have already been created during the lab setup.
The usermod command modifies a user's account. When used with the -a and -G options, it adds the user to a supplementary group without removing them from their existing groups.
Make sure you are still in the project directory:
cd ~/project
Now, add each user to the vr_designers group by executing the following commands one by one:
sudo usermod -a -G vr_designers user1
sudo usermod -a -G vr_designers user2
sudo usermod -a -G vr_designers user3
Let's understand the options used with the usermod command:
-a: This stands for "append" and ensures that the user is added to the group without being removed from other groups-G: This specifies the group to which the user will be addedvr_designers: The name of the groupuser1,user2,user3: The names of the users being added to the group
Similar to the groupadd command, usermod typically does not produce any output upon successful execution.
To verify that the users have been added to the group correctly, use the groups command:
groups user1 user2 user3
This command displays all the groups to which each user belongs. The output should look similar to:
user1 : user1 vr_designers
user2 : user2 vr_designers
user3 : user3 vr_designers
Each line shows a user followed by the groups they belong to. Now all three users are members of the vr_designers group along with their own primary groups (which have the same name as the username).
You have successfully added users to a group in Linux, which is a key step in managing permissions in a multi-user environment.
Checking Group Information
Now that you have created the vr_designers group and added users to it, it is important to understand how to retrieve and verify group information in Linux. This step will teach you several ways to check group-related information.
First, ensure you are in the project directory:
cd ~/project
Using the id Command
The id command provides detailed information about a user's identity, including their user ID (UID), primary group ID (GID), and all the groups they belong to. Let's check the group information for user1:
id user1
This command will display output similar to:
uid=1001(user1) gid=1001(user1) groups=1001(user1),1004(vr_designers)
This output shows:
uid=1001(user1): The user ID and usernamegid=1001(user1): The primary group ID and name (often the same as the username)groups=1001(user1),1004(vr_designers): All groups the user belongs to
Using the getent Command
Another useful command for checking group information is getent, which retrieves entries from various administrative databases, including the group database:
getent group vr_designers
You should see output similar to:
vr_designers:x:1004:user1,user2,user3
This output shows:
vr_designers: The group namex: A placeholder for the group password1004: The group ID (GID)user1,user2,user3: A list of all users who are members of this group
Examining the Group File Directly
You can also examine the /etc/group file, which stores all group information on the system:
cat /etc/group | grep vr_designers
The output should be similar to:
vr_designers:x:1004:user1,user2,user3
Checking Specific User's Group Membership
To specifically check which groups a user belongs to, you can use the groups command with a username:
groups user2
Output:
user2 : user2 vr_designers
These commands provide different ways to verify group information in Linux. Understanding and using these commands is essential for effective user and group management.
Summary
In this lab, you have learned the fundamental concepts and commands for managing groups in Linux. Here is a recap of what you have accomplished:
- You created a new group called
vr_designersusing thegroupaddcommand - You added multiple users to the group using the
usermodcommand with the-aand-Goptions - You learned various methods to check and verify group information using commands like
id,getent, andgroups
These skills are essential for Linux system administration, especially in multi-user environments where proper access control is crucial. Group management allows you to organize users effectively and assign permissions collectively, making system administration more efficient.
By understanding how to create groups, add users to groups, and verify group information, you are now equipped with the knowledge to manage user access in Linux systems.



