Understanding Users & Groups in Linux


Linux is a powerful operating system that follows a structured way of managing users and groups to maintain security and organization. If you've ever wondered how permissions work in Linux or why some commands need sudo
, this guide will break it all down in simple terms with real-world analogies.
1. What Are Users in Linux?
Think of Linux Like an Office Building π’
In an office, you have employees, each with their own ID cards and roles. Similarly, in Linux:
A user is like an employee.
A User ID (UID) is like their employee ID.
Permissions determine what they can or cannot do.
Types of Users in Linux
User Type | Description |
Root User (root ) | The boss of the system has all permissions (like the CEO). |
Regular Users | Normal users with limited access (like employees). |
System Users | Special users for background services like web servers and databases (like janitors/security). |
Root User (root
) β The Superuser
Has complete control over everything.
Can install software, delete files, and change system settings.
Command to switch to root:
sudo su
Check if you're root:
whoami # If it says "root", you have superuser access
Regular Users β Limited Access
Can create/edit files only in their own home directory (
/home/username
).Cannot install system-wide software.
Example:
bob
,alice
,ubuntu
are regular users.
System Users β Special Background Users
Used for services like
nginx
,mysql
, anddocker
.Cannot log in like normal users.
Example:
www-data
(for web servers),mysql
(for databases).
2. What Are Groups in Linux?
Groups = Departments in an Office π’
In an office, employees belong to departments (HR, IT, Finance). Groups in Linux work the same way:
A group is a collection of users with shared permissions.
Instead of giving permissions to each user individually, you add them to a group.
Types of Groups
Group Type | Description |
Primary Group | Every user belongs to a main group (usually named after their username). |
Secondary Groups | Users can be part of multiple groups to gain extra permissions. |
Common Linux Groups
Group Name | Purpose |
sudo | Allows users to run commands as root (sudo apt install ). |
docker | Lets users run Docker without sudo . |
www-data | Used by web servers (Nginx, Apache). |
adm | Allows access to system logs (/var/log/ ). |
3. How to Manage Users & Groups in Linux
Check Your User and Groups
whoami # Shows the current user
id # Shows user ID and group ID
groups # Lists all groups you belong to
Add a New User
sudo useradd -m alice # Create user 'alice' with a home directory
sudo passwd alice # Set password for 'alice'
Delete a User
sudo userdel -r alice # Remove user 'alice' and their home folder
Add a User to a Group
sudo usermod -aG docker alice # Add 'alice' to the 'docker' group
Remove a User from a Group
sudo deluser alice docker
List All Users
cat /etc/passwd # Shows all users on the system
List All Groups
cat /etc/group # Shows all available groups
4. Example Scenario: Office Security & Docker Access
Scenario 1: Office Access π
Bob is a Regular Employee (
bob
)He can only work in
/home/bob
.He canβt install software.
Alice is an IT Admin (
sudo
group)She can install software.
She can access all system files.
The Web Server (
www-data
system user)- Runs websites but canβt log in.
Scenario 2: Docker Access π’
Bob tries running Docker:
docker ps
β Permission Denied (Bob is not in the
docker
group).Admin adds Bob to the
docker
group:sudo usermod -aG docker bob
Bob logs out and logs back in, then tries again:
docker ps
β It works! Now Bob can run Docker without
sudo
.
5. Key Takeaways
Users are like employees, groups are like departments.
Root (Admin) can do everything, regular users have limited access.
Groups simplify permission management.
System users run services in the background (like Nginx, Docker, MySQL).
Adding a user to a group (like
docker
orsudo
) grants them special permissions.
By understanding users & groups, you can manage permissions securely and improve your Linux workflow! π
Subscribe to my newsletter
Read articles from Jasai Hansda directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Jasai Hansda
Jasai Hansda
Software Engineer (2 years) | In-transition to DevOps. Passionate about building and deploying software efficiently. Eager to leverage my development background in the DevOps and cloud computing world. Open to new opportunities!