1. Linux File Permissions — Concepts

The Three Permission Categories

Every file and directory has permissions defined for three categories of users:

Category Symbol Description
Owner (User) u The user who created the file
Group g The group that owns the file (primary group of the creator)
Others o Everyone else — not the owner and not in the owner group
All a Shortcut meaning u + g + o together

The Three Permission Types

Permission Symbol Octal For Files For Directories
Read r 4 Can read the file content Can list directory contents (ls)
Write w 2 Can edit the file Can add or remove files inside
Execute x 1 Can run the file as a program Can enter the directory (cd) and view permissions (ls -l)
No permission - 0 Nothing allowed Nothing allowed

How Permissions Appear in ls -l

drwxr-xr--  2  aliaa  aliaa  4096  Dec 14  Desktop
d  rwx  r-x  r--
|   |    |    |
|   |    |    Others permissions
|   |    Group permissions
|   Owner permissions
File type (d=directory, -=file, l=symlink, c=char device, b=block device)

Each of the three permission groups contains exactly 3 characters: r, w, x, or -.

The "Most Specific Permission" Rule

When determining what a user can do, Linux checks in order:

Is the user the OWNER?
    YES --> apply OWNER permissions
    NO  --> Is the user in the OWNER GROUP?
                YES --> apply GROUP permissions
                NO  --> apply OTHERS permissions

Permission Example

-rw-r--r--   aliaa   group1   file.txt
User Category matched Permissions
aliaa Owner read, write
User in group1 Group read only
Any other user Others read only

2. Changing Permissions — chmod