Permission denied errors, incorrect ownership, inaccessible directories and applications that cannot read or write files.
Inspect permissions and ownership with ls -l, then use chmod, chown or chgrp as appropriate.
Grant only the permissions required and avoid using broad recursive changes without first checking the target path.
What Are Linux File Permissions?
Linux uses file permissions to control access to files and directories. Each object has an owner, a group and permission settings for the owner, group and everyone else.
The three basic permissions are:
- r — read
- w — write
- x — execute
Check Permissions With ls -l
ls -l file.txt
Example:
-rw-r--r-- 1 bilal developers 1250 Sep 17 10:20 file.txt
The permission string is:
-rw-r--r--
The first character identifies the file type. The remaining nine characters represent permissions for owner, group and others.
Understand the Permission Groups
- rw- r-- r--
│ │ │
│ │ └── Others
│ └────── Group
└────────── Owner
For -rw-r--r--:
- Owner: read and write
- Group: read
- Others: read
Read, Write and Execute Permissions
Files
- Read: view file contents
- Write: modify file contents
- Execute: run the file as a program
Directories
- Read: list directory entries
- Write: create, delete or rename entries when other required permissions allow it
- Execute: access/traverse the directory
Useful Permission Commands
Inspect permissions
ls -l file.txt
Inspect ownership
stat file.txt
Change permissions
chmod 640 file.txt
Change owner
sudo chown user file.txt
Change group
sudo chgrp developers file.txt
Numeric Linux Permissions
Linux permissions can be represented numerically.
| Permission | Value |
|---|---|
| --- | 0 |
| --x | 1 |
| -w- | 2 |
| -wx | 3 |
| r-- | 4 |
| r-x | 5 |
| rw- | 6 |
| rwx | 7 |
What Does chmod 755 Mean?
chmod 755 script.sh
This produces:
rwxr-xr-x
- Owner: read, write, execute
- Group: read, execute
- Others: read, execute
What Does chmod 644 Mean?
chmod 644 file.txt
This produces:
rw-r--r--
This is commonly appropriate for ordinary non-executable files where the owner needs to edit the file and others only need read access.
What Does chmod 600 Mean?
chmod 600 secrets.txt
This produces:
rw-------
The owner has read/write access while group and other users have no permission bits.
Do not automatically apply restrictive permissions to files that need to be read by services or other users. Verify the application's requirements first.
Change Permissions With Symbolic Mode
chmod u+x script.sh
This adds execute permission for the owner.
chmod g+w shared.txt
This adds write permission for the group.
chmod o-r public.txt
This removes read permission from others.
Change Ownership With chown
sudo chown bilal file.txt
Change owner and group:
sudo chown bilal:developers file.txt
Verify:
ls -l file.txt
Change Group Ownership With chgrp
sudo chgrp developers project.txt
Then verify:
ls -l project.txt
Recursive Permissions: Use Carefully
The -R option applies a change recursively.
chmod -R 755 /path/to/directory
Applying the same permission mode to every file and directory can create security or functionality problems. Directories and regular files often need different permissions.
Safer Recursive Ownership Changes
Before changing a large directory tree, inspect the target:
ls -la /path/to/directory
Then inspect representative files:
find /path/to/directory -maxdepth 2 -ls
Only after confirming the intended scope should you use a recursive ownership change:
sudo chown -R user:group /path/to/directory
Check Effective Ownership
stat file.txt
Useful information includes:
- Owner
- Group
- Access mode
- File type
- Timestamps
Find Files With Specific Permissions
find /var/www -type f -perm 0777 -print
You can use this to identify files with an exact permission mode.
For security reviews, avoid assuming that every unusual permission is automatically a vulnerability. First understand the application's requirements.
Find World-Writable Files
find /path -type f -perm -0002 -print
Review the results before making changes.
Linux Permission Denied Troubleshooting
When you receive Permission denied, check these items:
- File or directory permissions
- Owner
- Group membership
- Parent directory permissions
- Process user
- ACLs if configured
- Security controls such as SELinux or AppArmor where applicable
Useful Permission Troubleshooting Commands
Check permissions
ls -ld /path/to/directory
ls -l /path/to/file
Check current user
id
Check another user's groups
id username
Inspect path components
namei -l /path/to/file
Inspect ACLs when available
getfacl /path/to/file
Why Directory Permissions Cause Confusion
A user may have read permission on a file but still be unable to access it because one of the parent directories does not allow traversal.
Check the entire path:
namei -l /var/www/app/config/settings.conf
Check Which User a Service Runs As
If an application cannot access a file, identify the account running it. For systemd services:
systemctl status nginx
Then inspect the service definition when necessary:
systemctl cat nginx
The process user must have the required access to the target path.
Example: Fix a Web Application Permission Problem
An application running as
www-data cannot read
/var/www/app/config.php.
First inspect:
ls -l /var/www/app/config.php
Check the path:
namei -l /var/www/app/config.php
If ownership or permissions are incorrect, make the smallest required change. For example:
sudo chown www-data:www-data /var/www/app/config.php
sudo chmod 640 /var/www/app/config.php
Then verify:
ls -l /var/www/app/config.php
Common chmod Mistakes
- Using
chmod 777as a generic fix - Applying
chmod -Rwithout checking the directory tree - Changing ownership without understanding the service account
- Ignoring parent directory permissions
- Changing permissions before collecting evidence
Why chmod 777 Should Not Be a Default Fix
chmod 777 file.txt
This grants read, write and execute permissions to owner, group and others. It may make an access problem disappear, but it also broadens access substantially.
Instead, identify which account requires access and grant only the required permissions.
Quick Permission Troubleshooting Path
Use this sequence before changing permissions:
- Identify the failing file or directory.
- Run
ls -lorls -ld. - Check owner and group.
- Check the process or user that requires access.
- Inspect parent directories with
namei -l. - Check ACLs if relevant.
- Make the smallest required change.
- Retest the original operation.
Permission Number Cheat Sheet
| Mode | Meaning |
|---|---|
600 | Owner read/write |
640 | Owner read/write, group read |
644 | Owner read/write, group and others read |
700 | Owner full access |
750 | Owner full, group read/execute |
755 | Owner full, group and others read/execute |
Practical Permission Workflow
Permission denied
↓
Identify file/path
↓
ls -l /path
↓
Check owner/group
↓
Check user/process
↓
namei -l /path
↓
Check ACL/security controls if needed
↓
Make smallest required change
↓
Retest
↓
Document