Understanding Users & Groups in Linux

Jasai HansdaJasai Hansda
4 min read

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 TypeDescription
Root User (root)The boss of the system has all permissions (like the CEO).
Regular UsersNormal users with limited access (like employees).
System UsersSpecial 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, and docker.

  • 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 TypeDescription
Primary GroupEvery user belongs to a main group (usually named after their username).
Secondary GroupsUsers can be part of multiple groups to gain extra permissions.

Common Linux Groups

Group NamePurpose
sudoAllows users to run commands as root (sudo apt install).
dockerLets users run Docker without sudo.
www-dataUsed by web servers (Nginx, Apache).
admAllows 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 🚒

  1. Bob tries running Docker:

     docker ps
    

    ❌ Permission Denied (Bob is not in the docker group).

  2. Admin adds Bob to the docker group:

     sudo usermod -aG docker bob
    
  3. 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 or sudo) grants them special permissions.

By understanding users & groups, you can manage permissions securely and improve your Linux workflow! πŸš€


0
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!