Jay Shree Krishna! Welcome to the official blog post for today’s RHCSA tutorial. If you’re preparing for the RHCSA exam, mastering user and group management is an essential skill. In this tutorial, we’ll cover how to create users and groups, assign secondary groups, and verify configurations using Linux commands.
RHCSA Question:
Create two users, “antara” and “aarav”, and a new group called “students”. Both users must be added to the “students” group as their secondary group without changing their primary groups.
Let’s dive into the step-by-step process!
Introduction to User and Group Management
User and group management is a fundamental task in Linux system administration. For the RHCSA exam, understanding primary and secondary groups is crucial, as they control user permissions and access to files.
- Primary Group: A user’s default group, typically created automatically with the same name as the user.
- Secondary Group: Additional groups that a user can belong to for broader access permissions.
In this tutorial, we’ll focus on managing both types using practical commands.
RHCSA Scenario Breakdown
Here’s the task:
- Create two users: “antara” and “aarav”.
- Create a new group: “students”.
- Add both users to the “students” group as a secondary group without changing their primary groups.
Step-by-Step Commands
Follow these steps to accomplish the task:
Step 1: Switch to the Root User
The commands we’ll use require root privileges. Switch to the root user:
sudo su
Step 2: Create the Users
Use the useradd command to create users:
useradd antara
useradd aarav
Step 3: Create the Group
Create a new group named “students” using the groupadd command:
groupadd students
Step 4: Add Users to the Secondary Group
Use the usermod command to add “antara” and “aarav” to the “students” group:
usermod -aG students antara
usermod -aG students aarav
-a: Append the group without removing existing group memberships.-G: Specify the secondary group.
Step 5: Verify the Configuration
To confirm that the users are part of the secondary group, use the groups command:
groups antara
groups aarav
Users have their primary group = their username and secondary group is students.
Verification and Best Practices
- Check All Group Memberships: Use the
idcommand to verify all groups for a user:
id antaraid aarav- Use Single-Line Commands: To save time, combine commands using a semicolon:
useradd antara; useradd aarav; groupadd students; usermod -aG students antara; usermod -aG students aarav- Test Permissions: Create a file accessible only to the “students” group and verify access.
touch /tmp/testfilechgrp students /tmp/testfilechmod 770 /tmp/testfilels -l /tmp/testfile
Key RHCSA Exam Tips
- Always verify your commands to ensure they produce the expected results.
- Familiarize yourself with common user and group management commands like
useradd,groupadd,usermod, andpasswd. - Practice all commands regularly to save time during the exam.
Conclusion
Congratulations! You’ve learned how to create users and groups, assign secondary groups, and verify configurations. These are essential skills for passing the RHCSA exam and managing Linux systems effectively.
If you found this tutorial helpful, don’t forget to check out my YouTube channel for more hands-on tutorials. Please like, share, and subscribe to support my work. Thank you, and Jay Shree Krishna!