Managing Users & Groups in Linux – A Complete Guide
📖 Introduction
Managing Users & Groups in Linux: Linux is a multi-user operating system, meaning multiple users can access the system simultaneously. Proper user and group management ensures security, organized access control, and streamlined administration.
This guide covers:
✅ Creating, modifying, and deleting users in Linux
✅ Managing groups for better access control
✅ Assigning sudo privileges
✅ Best practices for secure user management

1️⃣ Understanding Linux Users & Groups
Before diving into commands, let’s understand how Linux handles users and groups.
🔹 User Types in Linux
1️⃣ Root User – The superuser with full system control (UID 0
).
2️⃣ System Users – Used by system services and daemons (UIDs < 1000
).
3️⃣ Regular Users – Created for human users (UIDs ≥ 1000
).
🔹 Groups in Linux
- Primary Group: Assigned when a user is created.
- Supplementary Groups: Additional groups a user can be a part of.
📌 Command to View Users & Groups
cat /etc/passwd # View users
cat /etc/group # View groups
2️⃣ Creating and Managing Users in Linux
🔹 Add a New User
To create a new user with a default home directory:
sudo useradd -m alice
Set a password:
sudo passwd alice
📌 Explanation:
-m
creates a home directory (/home/alice
).passwd
assigns a password.
🔹 Modify an Existing User
Change username:
sudo usermod -l newalice alice
Change home directory:
sudo usermod -d /newhome/alice -m alice
Force password reset on next login:
sudo passwd --expire alice
🔹 Delete a User
sudo userdel alice
To remove the home directory as well:
sudo userdel -r alice
3️⃣ Managing Groups in Linux
🔹 Create a New Group
sudo groupadd developers
🔹 Add a User to a Group
sudo usermod -aG developers alice
📌 Best Practice: Always use -aG
to append a user to a group instead of overwriting existing groups.
🔹 View User’s Groups
groups alice
id alice
🔹 Remove a User from a Group
sudo gpasswd -d alice developers
4️⃣ Granting Sudo Privileges
🔹 Add a User to the Sudoers Group
For Ubuntu/Debian:
sudo usermod -aG sudo alice
For CentOS/RHEL:
sudo usermod -aG wheel alice
🔹 Test Sudo Access
sudo whoami
5️⃣ Best Practices for Secure User Management
✅ Use Strong Password Policies
Force password expiration every 90 days:
sudo chage -M 90 alice
Lock inactive accounts:
sudo usermod -L alice
✅ Restrict Root Access
Disable root login over SSH:
sudo nano /etc/ssh/sshd_config
Set: PermitRootLogin no
Restart SSH:
sudo systemctl restart sshd
✅ Monitor User Activity
Check recent logins:
last
Monitor failed login attempts:
cat /var/log/auth.log | grep "Failed password"
🔹 Summary
🔹 Learned how to create, modify, and delete users in Linux.
🔹 Explored group management for structured access control.
🔹 Discovered sudo privileges and security best practices.
💬 Have questions? Drop them in the comments below!
📌 Call to Action:
🔗 Want more Linux tutorials? Subscribe to TechNops.com for daily updates! 🚀