Linux File and Directory Permissions Explain Guide

Related Courses

Next Batch : Invalid Date

Understanding Users and Groups in Linux - Complete Guide for Real System Administration

Introduction: Why Users and Groups Matter in Linux

Linux is a multi-user operating system. Multiple users can work on the same system safely and independently. But how does Linux ensure that one user cannot access another user's data? How does the system control who can read, write, or execute files? How does it maintain security in shared environments?

The answer lies in Users and Groups.

Users and groups form the core of Linux security and access control. Understanding them is essential for system administrators, DevOps engineers, developers, and anyone managing Linux servers.

This guide explains everything clearly from user types to permissions, group management, authentication, and real-world administration.

The Core Idea: Identity and Access Control

Every action in Linux is performed by a User Identity (UID).

Linux does not trust names it trusts numbers.

  • Each user has a unique User ID (UID)

  • Each group has a unique Group ID (GID)

Permissions and access are controlled using UID and GID.

This structure ensures security and accountability.

Types of Users in Linux

Linux classifies users into three main categories.

1. Root User (Superuser)

The root user is the most powerful account in Linux.

Capabilities:

  • Full system control

  • Can modify any file

  • Can create/delete users

  • Can install/remove software

  • Can control services

  • Can override permissions

Root UID = 0

Because of its power, root access must be handled carefully.

2. System Users

System users are created automatically by the system for running services and processes.

Examples:

  • nginx

  • mysql

  • postgres

  • nobody

  • daemon

Characteristics:

  • No login shell (usually)

  • Used for background services

  • Improve system security

These users isolate services from each other.

3. Regular Users

These are human users who log in and work on the system.

Examples:

  • Developers

  • Administrators

  • Operators

  • Students

Regular users have limited permissions for safety.

Understanding Groups in Linux

A Group is a collection of users.

Purpose:

  • Share permissions

  • Manage access easily

  • Organize users logically

Example:
If five developers need access to a project folder, instead of assigning permissions individually, you create a group and add users to it.

Types of Groups

Primary Group

Every user belongs to one primary group.
When a user creates a file, the file automatically belongs to this group.

Secondary (Supplementary) Groups

Users can belong to multiple additional groups.
Used for shared access.

Example:
A developer may belong to:

  • developers group

  • docker group

  • sudo group

Important Files Related to Users and Groups

Linux stores user and group information in specific system files.

/etc/passwd - User Information

Contains:

  • Username

  • UID

  • GID

  • Home directory

  • Shell

Example entry:
john:x:1001:1001:/home/john:/bin/bash

/etc/shadow - Password Storage

Contains encrypted passwords and security settings.
Only root can access this file.

/etc/group - Group Information

Contains:

  • Group name

  • GID

  • Members

Example:
developers:x:1002:john,alice

Creating and Managing Users

Create User

useradd username

Create User with Home Directory

useradd -m username

Set Password

passwd username

Delete User

userdel username

Delete User with Home Directory

userdel -r username

Managing Groups

Create Group

groupadd groupname

Add User to Group

usermod -aG groupname username

Remove User from Group

gpasswd -d username groupname

Delete Group

groupdel groupname

Understanding File Ownership

Every file in Linux has:

  • Owner (User)

  • Group

  • Permissions

You can check using:
ls -l

Example output:
-rw-r--r-- 1 john developers file.txt

Meaning:

  • Owner = john

  • Group = developers

Changing Ownership

Change Owner

chown user file.txt

Change Owner and Group

chown user:group file.txt

Understanding Permissions

Permissions are assigned for:

  • Owner

  • Group

  • Others

Permission Types:

  • Read (r)

  • Write (w)

  • Execute (x)

Example:
chmod 755 file.sh

Meaning:

  • Owner → full access

  • Group → read + execute

  • Others → read + execute

Permissions protect data and system stability.

Sudo Access - Administrative Privileges

Regular users cannot perform administrative actions unless granted sudo access.

Users in sudo group can execute commands as root:
sudo apt update

This ensures controlled privilege escalation.

User Authentication Process

When a user logs in:

  1. Username checked in /etc/passwd

  2. Password verified using /etc/shadow

  3. UID assigned

  4. Shell loaded

  5. Home directory opened

  6. User session starts

Authentication ensures only authorized users access the system.

Real-World Use Cases

Shared Project Folder

Create group → Add developers → Assign folder permissions → All members collaborate safely.

Secure Server

Disable root login → Use sudo users → Limit permissions → Improve security.

Service Isolation

Run services using system users → Prevent cross-access → Increase stability.

Security Best Practices

  • Avoid direct root login

  • Use strong passwords

  • Grant minimal permissions

  • Use groups for access control

  • Monitor user activity

  • Remove unused users

  • Lock inactive accounts

Users and groups form the backbone of Linux security.

Frequently Asked Questions (FAQ)

1. What is UID in Linux?

Ans: UID is a unique numeric identifier assigned to each user.

2. What is GID?

Ans: GID is the unique identifier assigned to a group.

3. What is the root user?

Ans: Root is the superuser with full system control.

4. What is primary vs secondary group?

Ans: Primary group is default group of a user. Secondary groups provide additional access.

5. Where are user details stored?

Ans: In /etc/passwd, /etc/shadow, and /etc/group.

6. How do I give admin access to a user?

Add user to sudo group using usermod -aG sudo username.

7. How do permissions work?

Ans: Permissions control read, write, and execute access for owner, group, and others.

8. Can one user belong to multiple groups?

Ans: Yes, users can belong to multiple supplementary groups.

9. Why avoid root login?

Ans: For security. Root has full control and misuse can damage system.

10. Why are users and groups important?

Ans: They control security, access, and system organization.

Final Thoughts

Users and groups are the identity and security foundation of Linux. They control who can access what, how files are shared, and how systems remain secure in multi-user environments.

Mastering users and groups is essential for Linux administration, DevOps, and server management.