9. Manage Users and Groups
📘Red Hat Certified System Administrator (RHCSA – EX200)
Managing local users is a core Linux skill, and the RHCSA exam tests your ability to handle accounts quickly and correctly. Local users are accounts that exist only on the system (not on a network like LDAP).
We’ll cover:
- Understanding local user accounts
- Creating user accounts
- Deleting user accounts
- Modifying user accounts
- Exam tips and examples
1. Understanding Local User Accounts
In Linux, every user has:
- Username – e.g.,
alice - User ID (UID) – a number, usually starting at 1000 for regular users
- Primary group – usually a group with the same name as the username
- Home directory – where the user’s files are stored, e.g.,
/home/alice - Shell – the command-line interface the user uses, e.g.,
/bin/bash
Key files to know:
/etc/passwd– stores user account info (username, UID, home directory, shell)/etc/shadow– stores encrypted passwords and password settings/etc/group– stores group information
IT example: A system administrator creates accounts for employees so they can log in, access resources, and have personal directories.
2. Creating User Accounts
Linux provides the useradd command for creating users.
Basic syntax:
useradd [options] username
Most common options:
| Option | Purpose |
|---|---|
-m | Create a home directory if it doesn’t exist |
-s | Set default shell (e.g., /bin/bash) |
-d | Specify custom home directory |
-c | Add a comment (usually full name) |
-G | Add user to additional groups |
Example 1: Basic user
sudo useradd -m alice
sudo passwd alice
-mcreates/home/alicepasswdsets the password foralice- The user can now log in
Example 2: User with custom shell and comment
sudo useradd -m -s /bin/bash -c "Alice, IT Support" alice
sudo passwd alice
- IT example: Alice needs
/bin/bashto run scripts for system maintenance.
Checking the user
id alice
Output shows:
uid=1001(alice) gid=1001(alice) groups=1001(alice)
- Confirms UID, GID, and groups
3. Deleting User Accounts
To remove a user, use the userdel command.
Syntax:
sudo userdel [options] username
Options:
| Option | Purpose |
|---|---|
-r | Remove the user’s home directory and mail spool |
Example 1: Delete user but keep home directory
sudo userdel alice
- Alice’s account is gone, but
/home/aliceremains
Example 2: Delete user and home directory
sudo userdel -r alice
- Deletes account and
/home/alicecompletely - IT example: When an employee leaves the company, their files are also removed if necessary.
4. Modifying User Accounts
The usermod command lets you change an existing account.
Basic syntax:
sudo usermod [options] username
Common options:
| Option | Purpose |
|---|---|
-l newname | Change username |
-d /new/home -m | Move home directory |
-s /new/shell | Change login shell |
-G group1,group2 | Add user to supplementary groups |
Example 1: Change username
sudo usermod -l bob alice
- Alice is now
bob, but her home directory stays/home/aliceunless you also move it
Example 2: Change home directory and move files
sudo usermod -d /home/bob -m bob
- Moves files from old home directory to new one
Example 3: Add user to groups
sudo usermod -aG wheel,sudo bob
- Adds
bobtowheelandsudogroups -aGis important; without-a, you replace all existing groups
5. Exam Tips
- Always create a home directory for new users:
-m - Use
passwdto set passwords after creating accounts - Check users with
id usernameorgetent passwd username - Deleting a user with
-rremoves all their data — important for cleanup - To modify groups, use
usermod -aG group usernameto avoid removing existing groups - RHCSA may ask you to create users, modify their shell/home, and delete them
6. Quick Commands Summary
| Task | Command Example |
|---|---|
| Create user with home | sudo useradd -m alice |
| Set password | sudo passwd alice |
| Delete user | sudo userdel alice |
| Delete user with home | sudo userdel -r alice |
| Modify username | sudo usermod -l bob alice |
| Change home directory | sudo usermod -d /home/bob -m bob |
| Add user to group | sudo usermod -aG wheel,sudo bob |
| Check user info | id bob |
✅ Key points for the RHCSA exam:
- Know
useradd,usermod,userdel,passwd - Understand home directories, shells, and groups
- Practice creating, deleting, and modifying users quickly
