```html Linux File Permissions Explained: chmod, chown & chgrp | TechRunbook
TECHRUNBOOK · PRACTICAL GUIDE

Linux File Permissions Explained: chmod, chown & chgrp

Understand Linux file permissions, ownership, chmod, chown, chgrp, numeric permissions and practical troubleshooting examples.

Practical Runbook Linux Administration
Practical Guide 30 Sections Issues → Solutions → Recommendations
Have a Linux permissions question? Post your issue to the TechRunbook Community and get help from other IT professionals.
Ask the Community →
!Issue

Permission denied errors, incorrect ownership, inaccessible directories and applications that cannot read or write files.

Solution

Inspect permissions and ownership with ls -l, then use chmod, chown or chgrp as appropriate.

Recommendations

Grant only the permissions required and avoid using broad recursive changes without first checking the target path.

TechRunbook approach: Inspect first, understand owner/group/permission bits, make the smallest required change, and verify the result.
01

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
02

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.

03

Understand the Permission Groups

- rw- r-- r--
  │   │   │
  │   │   └── Others
  │   └────── Group
  └────────── Owner

For -rw-r--r--:

  • Owner: read and write
  • Group: read
  • Others: read
04

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
05

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
06

Numeric Linux Permissions

Linux permissions can be represented numerically.

PermissionValue
---0
--x1
-w-2
-wx3
r--4
r-x5
rw-6
rwx7
07

What Does chmod 755 Mean?

chmod 755 script.sh

This produces:

rwxr-xr-x
  • Owner: read, write, execute
  • Group: read, execute
  • Others: read, execute
08

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.

09

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.

Security note:

Do not automatically apply restrictive permissions to files that need to be read by services or other users. Verify the application's requirements first.

10

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.

11

Change Ownership With chown

sudo chown bilal file.txt

Change owner and group:

sudo chown bilal:developers file.txt

Verify:

ls -l file.txt
12

Change Group Ownership With chgrp

sudo chgrp developers project.txt

Then verify:

ls -l project.txt
13

Recursive Permissions: Use Carefully

The -R option applies a change recursively.

chmod -R 755 /path/to/directory
Be careful with recursive chmod.

Applying the same permission mode to every file and directory can create security or functionality problems. Directories and regular files often need different permissions.

14

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
15

Check Effective Ownership

stat file.txt

Useful information includes:

  • Owner
  • Group
  • Access mode
  • File type
  • Timestamps
16

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.

17

Find World-Writable Files

find /path -type f -perm -0002 -print

Review the results before making changes.

18

Linux Permission Denied Troubleshooting

When you receive Permission denied, check these items:

  1. File or directory permissions
  2. Owner
  3. Group membership
  4. Parent directory permissions
  5. Process user
  6. ACLs if configured
  7. Security controls such as SELinux or AppArmor where applicable
19

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
20

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
21

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.

22

Example: Fix a Web Application Permission Problem

Scenario
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
23

Common chmod Mistakes

  • Using chmod 777 as a generic fix
  • Applying chmod -R without checking the directory tree
  • Changing ownership without understanding the service account
  • Ignoring parent directory permissions
  • Changing permissions before collecting evidence
24

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.

25

Quick Permission Troubleshooting Path

Use this sequence before changing permissions:

  1. Identify the failing file or directory.
  2. Run ls -l or ls -ld.
  3. Check owner and group.
  4. Check the process or user that requires access.
  5. Inspect parent directories with namei -l.
  6. Check ACLs if relevant.
  7. Make the smallest required change.
  8. Retest the original operation.
26

Permission Number Cheat Sheet

ModeMeaning
600Owner read/write
640Owner read/write, group read
644Owner read/write, group and others read
700Owner full access
750Owner full, group read/execute
755Owner full, group and others read/execute
27

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
28

Frequently Asked Questions

What are Linux file permissions?

Linux file permissions control who can read, write or execute files and who can access directories.

How do I check Linux file permissions?

Use ls -l filename or stat filename.

What does chmod 755 mean?

The owner gets read, write and execute permissions. Group and others get read and execute permissions.

How do I change ownership?

Use chown, for example: sudo chown user:group file.txt.

Why should I avoid chmod 777?

It grants broad permissions to all users. A narrower permission mode is usually preferable when it meets the application's requirements.

29

Related TechRunbook Guides

Was this guide helpful?
↑ Top ```