π― Introduction
In this tutorial, weβll learn how to create users and groups in RHEL, a key topic in RHCSA (Red Hat Certified System Administrator) certification. Youβll understand not just the commands, but also the real-world purpose of users and groups β using simple examples.
Letβs get started!
π€ Why Do We Create Users and Groups?
Imagine Linux as an office building:
-
Users are the employees β each person needs their own login and workspace.
-
Groups are departments β like βSalesβ or βITβ, which control shared access to resources.
So, in RHEL, users and groups help us manage:
-
Who can access what
-
Who owns which files
-
Who can run specific commands
π§βπ» 1. Creating a User
β Basic Command:
sudo useradd <username>
β Example:
sudo useradd alice
This creates a new user named alice
.
π Behind the scenes: This command updates
/etc/passwd
, creates a home directory (if default settings apply), and assigns a UID.
π Set a Password:
sudo passwd alice
The system will prompt you to enter and confirm a password.
π¨βπ©βπ§ 2. Creating a Group
β Basic Command:
sudo groupadd <groupname>
β Example:
sudo groupadd developers
This creates a new group named developers
.
π₯ 3. Add a User to a Group
There are two types of group membership:
-
Primary group (only one per user)
-
Secondary group(s) (can be multiple)
β Change Primary Group:
sudo usermod -g <groupname> <username>
Example:
sudo usermod -g developers alice
Now, developers
is the main group for alice
.
β Add to Secondary Group:
sudo usermod -aG <groupname> <username>
Example:
sudo usermod -aG wheel alice
Now alice
is also a member of the wheel
group (used for sudo/root access).
β οΈ Important: Always use the
-a
(append) option with-G
, or youβll overwrite all existing secondary groups.
π 4. Create User with Group in One Command
sudo useradd -g developers -G wheel alice
This:
-
Sets
developers
as the primary group -
Adds
alice
to thewheel
group as secondary
Set password as usual:
sudo passwd alice
π 5. View User & Group Information
Check user's group membership:
groups alice
View user account info:
id alice
View group details:
getent group developers
π§Ή 6. Delete User or Group
Delete user (keep files):
sudo userdel alice
Delete user (and home directory):
sudo userdel -r alice
Delete group:
sudo groupdel developers
β οΈ Make sure no user is using the group before deleting.
β Summary / Key Takeaways
Task | Command |
---|---|
Create user |
|
Set password |
|
Create group |
|
Set primary group |
|
Add to secondary group |
|
View groups |
|
Delete user |
|
Delete group |
|
π¬ Final Thoughts
Thatβs it! Youβve just learned the essential commands and concepts for managing users and groups in RHEL β a skill youβll use daily as a Linux sysadmin.
π Think of users and groups as your access control system, helping you organize and secure your Linux environment.