Understanding Permissions
You try to run a script: "Permission denied." You try to edit a config: "Permission denied." You try to access a directory: "Permission denied."
This chapter fixes that. Let's understand how Linux permissions work.
Why Permissions Exist
Linux is a multi-user system. Even on your personal laptop, there's:
- Your user account
- The root superuser
- System service accounts (nginx, mysql, etc.)
Permissions control who can do what. Without them, any user could read your private files, delete system configs, or crash services.
The Three Permissions
Every file has three basic permissions:
| Permission | Letter | Meaning |
|---|---|---|
| Read | r | View file contents |
| Write | w | Modify file contents |
| Execute | x | Run the file as a program |
For directories, they mean slightly different things:
| Permission | For Files | For Directories |
|---|---|---|
| Read (r) | View contents | List files |
| Write (w) | Modify contents | Create/delete files |
| Execute (x) | Run as program | Enter the directory |
Directory Execute - The Most Confusing Part
You need x (execute) permission on a directory to cd into it or access files inside. This is the #1 source of permission confusion:
- Read (r) on a directory = can list filenames
- Execute (x) on a directory = can enter and access files
- Without
x, you can see names but can't access anything inside
The Three User Classes
Permissions apply to three classes of users:
| Class | Symbol | Description |
|---|---|---|
| Owner | u | The user who owns the file |
| Group | g | Users in the file's group |
| Others | o | Everyone else |
Every file has:
- One owner (a user)
- One group (a collection of users)
Permissions are checked in order:
- If you're the owner → owner permissions apply
- Else if you're in the group → group permissions apply
- Else → others permissions apply
Visualizing Permissions
-rwxr-xr--
│└┬┘└┬┘└┬┘
│ │ │ └── Others: read only
│ │ └───── Group: read + execute
│ └──────── Owner: read + write + execute
└────────── File type (- = file, d = directory)
This is what you see with ls -l.
Permission Examples
| Permission | Meaning |
|---|---|
rwx------ | Owner has full access, nobody else |
rw-r--r-- | Owner can edit, others can read |
rwxr-xr-x | Owner can edit+run, others can run |
rw-rw---- | Owner and group can edit |
--------- | Nobody can do anything |
The Numeric System (Preview)
Each permission has a number:
- r = 4
- w = 2
- x = 1
Add them up for each class:
rwx= 4+2+1 = 7r-x= 4+0+1 = 5r--= 4+0+0 = 4
So rwxr-xr-- = 754
We'll cover this in detail later.
What does it mean if you have 'r' but not 'x' permission on a directory?
Key Takeaways
- Three permissions: read (r), write (w), execute (x)
- Three user classes: owner (u), group (g), others (o)
- Directories need execute (x) permission to enter
- Permissions are checked in order: owner → group → others
ls -lshows permissions in the formatrwxrwxrwx
Next: how to read and interpret permission strings from ls -l.