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
- Add a New User
- Add User with Home Directory and Comment
- Modify a User
- Lock/Unlock a User
- Delete a User
- Group Management
- View User and Group Details
- Create a Sudo User
- Try It Yourself
- Real-World Scenarios
- Why This Matters
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
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.
Delete a User
sudo userdel -r johnd
-r: removes home directory too
Group Management
Create a new group:
sudo groupadd developers
Add user to group:
sudo usermod -aG developers john
List user’s groups:
groups john
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
sudo usermod -aG wheel alice
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.