Create, delete, and modify local user accounts

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:

  1. Understanding local user accounts
  2. Creating user accounts
  3. Deleting user accounts
  4. Modifying user accounts
  5. 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:

OptionPurpose
-mCreate a home directory if it doesn’t exist
-sSet default shell (e.g., /bin/bash)
-dSpecify custom home directory
-cAdd a comment (usually full name)
-GAdd user to additional groups

Example 1: Basic user

sudo useradd -m alice
sudo passwd alice
  • -m creates /home/alice
  • passwd sets the password for alice
  • 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/bash to 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:

OptionPurpose
-rRemove 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/alice remains

Example 2: Delete user and home directory

sudo userdel -r alice
  • Deletes account and /home/alice completely
  • 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:

OptionPurpose
-l newnameChange username
-d /new/home -mMove home directory
-s /new/shellChange login shell
-G group1,group2Add user to supplementary groups

Example 1: Change username

sudo usermod -l bob alice
  • Alice is now bob, but her home directory stays /home/alice unless 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 bob to wheel and sudo groups
  • -aG is important; without -a, you replace all existing groups

5. Exam Tips

  • Always create a home directory for new users: -m
  • Use passwd to set passwords after creating accounts
  • Check users with id username or getent passwd username
  • Deleting a user with -r removes all their data — important for cleanup
  • To modify groups, use usermod -aG group username to avoid removing existing groups
  • RHCSA may ask you to create users, modify their shell/home, and delete them

6. Quick Commands Summary

TaskCommand Example
Create user with homesudo useradd -m alice
Set passwordsudo passwd alice
Delete usersudo userdel alice
Delete user with homesudo userdel -r alice
Modify usernamesudo usermod -l bob alice
Change home directorysudo usermod -d /home/bob -m bob
Add user to groupsudo usermod -aG wheel,sudo bob
Check user infoid 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
Buy Me a Coffee