Welcome to Day 21 of the 30 Days of Linux Challenge!

Today I focused on one of the most fundamental sysadmin tasks: managing users and groups.

If you’re running multi-user servers, managing team access, or securing a Linux system, user and group management is at the core of everything.

📚 Table of Contents

Why User Management Matters

In a multi-user system:

  • Everyone needs secure, isolated access
  • Permissions are tied to users and groups
  • Services run under user IDs (UIDs)

Good user management = better control, security, and scalability.

Add a New User

sudo useradd ali
sudo passwd ali

This:

  • Adds user to /etc/passwd
  • Sets home directory, shell, and default group

Image description

Add User with Home Directory and Comment

sudo useradd -m -c "John Doe" johnd

Flags:

-m → create home directory

-c → add a description/comment

Modify a User

Change username:
sudo usermod -l newname oldname

Move home directory:
sudo usermod -d /new/path -m user

Lock/Unlock a User

Lock:
sudo usermod -L ali

Unlock:
sudo usermod -U ali

Useful for temporarily suspending accounts.

Image description

Delete a User

sudo userdel -r johnd

-r: removes home directory too

Group Management

Create a new group:

sudo groupadd developers

Image description

Add user to group:
sudo usermod -aG developers john

Image description

List user’s groups:
groups john

Image description

Change primary group:
sudo usermod -g admins john

View User and Group Details

File Description
/etc/passwd User details (UID, home, shell)
/etc/shadow Encrypted passwords + expiration
/etc/group Group definitions and memberships

View a user's entry:
grep john /etc/passwd

Create a Sudo User

sudo useradd alice

sudo passwd alice

Image description

sudo usermod -aG wheel alice

Image description

Red Hat-based systems use the wheel group for sudo access.

Try It Yourself

Add a user with a home directory

sudo useradd -m testuser

Set password

sudo passwd testuser

Add to a group

sudo groupadd testers
sudo usermod -aG testers testuser

Lock and unlock

sudo usermod -L testuser
sudo usermod -U testuser

Delete user and home

sudo userdel -r testuser

Real-World Scenarios

Scenario Tool/Command
Add a new developer useradd, passwd, groupadd
Add user to project groups usermod -aG
Create a sudo admin usermod -aG wheel
Temporarily suspend user usermod -L
Cleanly remove a user userdel -r

Why This Matters

Linux permissions, access control, and identity management all revolve around users and groups.

As a sysadmin or DevOps engineer, you’ll:

  • Onboard and offboard users
  • Grant precise access to services
  • Protect systems from unauthorized entry
  • Mastering user management is foundational to secure and efficient Linux administration.