Are you one of those people who runs:
chmod 777 -R /folder
every time you encounter a Linux permission issue?
I am. 😂
It works. The error disappears. Problem solved... right?
Not exactly.
Giving everyone full permission is usually a sign that we are fixing the symptom instead of understanding the actual problem.
Let's take a look at how Linux file permissions really work.
The Three Permission Types
Every file and directory in Linux has three basic permissions:
| Permission | Symbol | Value | Meaning |
|---|---|---|---|
| Read | r |
4 | View contents |
| Write | w |
2 | Modify contents |
| Execute | x |
1 | Execute/access |
The numeric values are used when setting permissions with chmod.
For example:
rwx = 4 + 2 + 1 = 7
rw- = 4 + 2 + 0 = 6
r-x = 4 + 0 + 1 = 5
The Three User Categories
Linux permissions are divided into three groups:
u → user (file owner)
g → group (users belonging to the file group)
o → other (everyone else)
When you run:
ls -l
you might see:
-rwxrw-r-x
Let's break it down.
- rwx rw- r-x
│ │ │ │
│ │ │ └── Other users
│ │ └────── Group
│ └────────── Owner
└──────────── File type
The first character represents the file type:
- regular file
d directory
Understanding Numeric Permissions
Example:
-rwxrw-r-x
Owner:
rwx = 4 + 2 + 1 = 7
Group:
rw- = 4 + 2 + 0 = 6
Other:
r-x = 4 + 0 + 1 = 5
Therefore:
chmod 765 file
means:
Owner → rwx
Group → rw-
Other → r-x
Changing Permissions with chmod
There are two common ways to use chmod.
Numeric mode
Example:
chmod 755 script.sh
Meaning:
Owner → rwx (7)
Group → r-x (5)
Other → r-x (5)
Result:
-rwxr-xr-x
2. Symbolic mode
Instead of calculating numbers, we can directly modify permissions.
Remove read permission from others:
chmod o-r file
Before:
-rwxr--r--
After:
-rwxr-----
Add execute permission for the owner:
chmod u+x file
Before:
-rw-r--r--
After:
-rwxr--r--
If no target is specified:
chmod +x file
it applies to all permission groups.
Before:
-rw-r--r--
After:
-rwxr-xr-x
Directory Permissions Are Different
One important detail:
Directories do not behave exactly like files.
For directories:
| Permission | Meaning |
|---|---|
r |
List files inside |
w |
Create/delete files |
x |
Enter/access directory |
For example:
chmod 755 folder
allows:
- Owner: full access
- Others: enter and read files
Without the execute permission:
chmod 644 folder
you may see the directory name, but you cannot access files inside.
Why chmod 777 Is Usually a Bad Idea
chmod 777 gives:
Owner → rwx
Group → rwx
Other → rwx
Meaning every user and process on the system can modify the files.
For example:
chmod 777 uploads/
might temporarily fix an application issue, but it can introduce security problems.
A better approach is usually to fix ownership:
chown user:group uploads/
chmod 755 uploads/
The correct permission depends on who actually needs access.
Next Time You See "Permission Denied"
Before running:
chmod 777 -R /folder
try checking:
ls -l
Then ask:
- Who owns this file?
- Which group owns it?
- Does the user have the required permission?
- Is the directory missing the execute permission?
Linux permissions are not complicated.
Once you understand:
- three permission bits (
rwx) - three ownership groups (
ugo) - numeric permissions (
755,644, etc.)
most permission issues become much easier to debug.
Use the permission you need, not the maximum permission available.
Top comments (0)