đ¤ Users and Permissions¶
Understanding how Linux manages users, groups, ownership and access control.
Table of Contents¶
- Why Users Exist
- Users
- Groups
- Root User
- Sudo
- Authentication vs Authorization
- Ownership
- Permission Model
- Read, Write and Execute
- Viewing Permissions
- chmod
- Numeric Permissions
- Symbolic Permissions
- chown
- Useful User Commands
- Useful Group Commands
- Security Principles
- Mental Model
1ī¸âŖ Why Users Exist¶
Linux was designed as a multi-user operating system.
Without users and permissions:
Everyone could access everything
which would be a major security risk.
Users allow Linux to identify:
- who is performing an action
- who owns a file
- who can access a resource
2ī¸âŖ Users¶
A user represents an identity inside Linux.
Examples:
sara
student
admin
Users can:
- own files
- run processes
- belong to groups
- access resources
Every action performed on Linux is associated with a user.
Viewing Current User¶
whoami
Displays the current logged-in user.
Example:
sara
Viewing User Information¶
id
Displays:
- User ID (UID)
- Group ID (GID)
- Group memberships
Example:
uid=1000(sara)
gid=1000(sara)
groups=1000(sara),27(sudo)
3ī¸âŖ Groups¶
Groups allow permissions to be assigned to multiple users simultaneously.
Instead of managing:
Sara
John
Maria
individually, Linux can use:
developers
and assign permissions to the group.
Viewing Groups¶
groups
Displays groups associated with the current user.
Creating Groups¶
groupadd developers
Creates a new group.
Adding Users to Groups¶
usermod -aG developers sara
Adds a user to a group.
Why Groups Matter¶
Groups simplify permission management.
Instead of assigning permissions individually, permissions can be assigned once to a group.
4ī¸âŖ Root User¶
Root is the administrator account.
Root has unrestricted access.
Root can:
- install software
- create users
- remove users
- modify system configuration
- change permissions
Think of root as:
The owner of the entire system
5ī¸âŖ Sudo¶
Instead of logging directly as root, Linux commonly uses:
sudo command
Example:
sudo apt update
Sudo allows:
Temporary administrator privileges
Benefits:
- accountability
- logging
- better security
6ī¸âŖ Authentication vs Authorization¶
These concepts are different.
Authentication¶
Answers:
Who are you?
Examples:
- Passwords
- SSH Keys
Authorization¶
Answers:
What are you allowed to do?
Examples:
- Read files
- Modify files
- Install software
Authentication identifies.
Authorization grants permissions.
7ī¸âŖ Ownership¶
Every file has:
- an owner
- a group owner
Example:
Owner: sara
Group: developers
Ownership determines who controls the resource.
Viewing Ownership¶
ls -l
Example:
-rw-r--r-- 1 sara developers file.txt
8ī¸âŖ Permission Model¶
Linux uses three permission categories.
Owner
Group
Others
Each category receives different permissions.
9ī¸âŖ Read, Write and Execute¶
Linux permissions are built around three actions.
Read (r)¶
Allows viewing content.
Examples:
- open files
- view directories
Write (w)¶
Allows modifications.
Examples:
- edit files
- create files
- delete files
Execute (x)¶
Allows execution.
Examples:
- run programs
- run shell scripts
đ Viewing Permissions¶
Example:
-rwxr-xr--
Breakdown:
rwx | r-x | r--
Owner | Group | Others
Meaning:
Owner:
- Read
- Write
- Execute
Group:
- Read
- Execute
Others:
- Read
1ī¸âŖ1ī¸âŖ chmod¶
chmod means:
Change Mode
Used to modify permissions.
Example:
chmod 755 script.sh
Changes file permissions.
Making a script executable:
chmod +x script.sh
One of the most common uses of chmod.
Removing write permission:
chmod -w file.txt
1ī¸âŖ2ī¸âŖ Numeric Permissions¶
Linux can represent permissions numerically.
Common values:
755
744
700
644
Relationship:
r = 4
w = 2
x = 1
Examples:
7 = rwx
6 = rw-
5 = r-x
4 = r--
Example:
chmod 644 file.txt
1ī¸âŖ3ī¸âŖ Symbolic Permissions¶
Instead of numbers, permissions can be modified symbolically.
Examples:
chmod +x script.sh
chmod -w file.txt
chmod g+w file.txt
Symbolic mode focuses on:
Adding or removing permissions
1ī¸âŖ4ī¸âŖ chown¶
chown means:
Change Owner
Used to transfer ownership.
Example:
chown sara file.txt
Changes the owner.
Changing owner and group:
chown sara:developers file.txt
Ownership and permissions work together.
1ī¸âŖ5ī¸âŖ Useful User Commands¶
Display current user:
whoami
Display user information:
id
Create a user:
useradd username
Delete a user:
userdel username
1ī¸âŖ6ī¸âŖ Useful Group Commands¶
Display groups:
groups
Create group:
groupadd developers
Modify group membership:
usermod -aG developers sara
Delete group:
groupdel developers
1ī¸âŖ7ī¸âŖ Security Principles¶
Linux permissions follow important security concepts.
Least Privilege¶
Give users only the permissions they need.
Separation of Responsibilities¶
Different users perform different tasks.
Access Control¶
Protect resources according to their importance.
Permissions are one of Linux's primary security mechanisms.
1ī¸âŖ8ī¸âŖ Mental Model¶
Imagine an office building.
Users are:
Employees
Groups are:
Departments
Files are:
Documents
Permissions are:
Access badges
Root is:
The building owner
Final Mental Image
Users
â
Groups
â
Permissions
â
Security
Linux uses this hierarchy to control who can access what.