Understanding chmod: Linux File Permissions Explained

Learn how chmod works, how to read rwx permissions, and which numeric settings to use for common Linux file and directory scenarios.

chmod is a Linux command-line tool that sets file and directory permissions for owner, group, and others.

It is useful when you need to fix Permission denied errors, make scripts executable, or lock down sensitive files.

It does not change file ownership, ACL policy, or security framework rules.

Quick Answer

If you only need the common cases:

  • chmod 644 file.txt for normal text or config files
  • chmod 755 script.sh for executable scripts
  • chmod 600 secret.env for private credential files
  • chmod 755 dir/ for directories that others must traverse

These values are shorthand for read (r), write (w), and execute (x) permissions across three groups.

How chmod Permissions Work

Linux permissions are evaluated across three groups:

Group Symbol Meaning
Owner u User who owns the file
Group g Users in the file's group
Others o Everyone else

Each group can have three bits:

Permission Symbol Numeric Value Files Directories
Read r 4 Read file contents List entries
Write w 2 Modify file contents Create, rename, delete entries
Execute x 1 Run file as program/script Traverse directory path

Numeric (Octal) Math

Each digit is a sum of 4 + 2 + 1:

  • 7 = rwx
  • 6 = rw-
  • 5 = r-x
  • 4 = r--
  • 0 = ---

So 755 means:

  • Owner: 7 = rwx
  • Group: 5 = r-x
  • Others: 5 = r-x

Symbolic vs Numeric chmod

Numeric Syntax

chmod 644 notes.txt
chmod 755 deploy.sh
chmod 600 .env

Numeric mode is fast when you already know the final target state.

Symbolic Syntax

chmod u+x deploy.sh   # add execute to owner
chmod g-w data.csv    # remove write from group
chmod o=r report.txt  # set others to read only
chmod a+r LICENSE     # add read for all

Symbolic mode is safer when you want to adjust only one permission bit.

Worked Examples

Example 1: Make a Script Executable

Input state:

-rw-r--r-- 1 dev dev 920 backup.sh

Apply:

chmod 755 backup.sh

Result:

-rwxr-xr-x 1 dev dev 920 backup.sh

Why this works: the script needs x to run, and 755 keeps write permission restricted to the owner.

Example 2: Lock Down a Secrets File

Input state:

-rw-r--r-- 1 dev dev 120 .env

Apply:

chmod 600 .env

Result:

-rw------- 1 dev dev 120 .env

Only the owner can read or edit sensitive values.

Example 3: Edge Case - Recursive Directory Fix

A common web project target is:

  • directories: 755
  • files: 644

Safer commands:

find public -type d -exec chmod 755 {} +
find public -type f -exec chmod 644 {} +

This avoids the frequent mistake of setting executable bits on every file.

Common Permission Sets

Use Case Typical Mode Notes
Regular document or config 644 Readable by others, writable by owner
Executable script or binary 755 Executable for all, writable by owner
Private key or secrets file 600 Owner-only read/write
Private directory 700 Owner-only access
Shared read-only file 444 No writes for anyone

Common Mistakes and Fixes

1. Using 777 as a Shortcut

chmod 777 upload-dir

This grants write access to everyone and is rarely justified.

Better approach:

  • set the correct owner/group with chown
  • use least-privilege mode such as 755, 775, or 750

2. Forgetting Directory Execute Permission

chmod 644 mydir can make a directory unusable for traversal.

Use 755 (or stricter variants like 750) for directories that must be entered.

3. Recursive chmod Without File/Directory Split

chmod -R 755 project/ makes every file executable, which is often incorrect.

Prefer separate find commands so file and directory modes differ.

4. Fixing Mode Bits When Ownership Is Wrong

If ownership is wrong, chmod alone won’t fix write failures.

Inspect with:

ls -l path/to/file

Then fix owner/group first (if needed), then permissions.

Practical Decision Rules

Use these defaults unless your environment requires something else:

  • Use 644 for most non-executable files.
  • Use 755 for scripts users/processes must execute.
  • Use 600 for credential files.
  • Use 700 for private directories.
  • Use symbolic mode when changing one bit, numeric mode when setting final state.

Compare: chmod vs Related Commands

Command Primary Job Changes mode bits? Changes owner/group?
chmod Set rwx permission bits Yes No
chown Change owner and/or group No Yes
umask Default permission mask for new files Indirectly No

Verify Your Changes

After applying permissions, check the result directly:

ls -l file-or-dir

For deeper inspection:

namei -l /full/path/to/file

namei -l helps debug path traversal permissions on each directory component.

Convert rwx and Numeric Modes

Unix Permissions Calculator

Use this tool to convert between symbolic permissions (`rwxr-xr--`) and numeric modes (`754`) before running chmod.

Open Calculator

FAQ

What does chmod do in Linux?

chmod sets permission bits for owner, group, and others on files or directories.

What is the difference between chmod 644 and chmod 755?

644 is non-executable for group/others, while 755 includes execute permission and is typical for scripts and directories.

Why does a directory need execute permission?

For directories, execute means traversal. Without it, users cannot cd into the directory path.

Is chmod 777 safe?

Usually no. It grants universal write access and should generally be avoided.

How can I recursively set 644 for files and 755 for directories?

Use two commands:

find target -type f -exec chmod 644 {} +
find target -type d -exec chmod 755 {} +

What does chmod u+x mean?

It adds execute permission for the file owner only and leaves other bits unchanged.

Why do I still get Permission denied after chmod?

Possible causes include wrong ownership, missing directory traversal permissions, ACL restrictions, SELinux/AppArmor policy, or mount options.

Does chmod change owner or group?

No. Use chown to change owner/group metadata.

What does chmod -R do?

It applies permission changes recursively to all nested files and directories under the given path.

Is chmod enough for every Linux permission problem?

No. It only controls standard mode bits and does not replace ownership, ACL, or mandatory access control changes.

Related Reading

Trust and Limitations

This guide explains standard Linux/Unix permission bits. Some environments add ACLs, container mount policies, or MAC frameworks (SELinux/AppArmor) that enforce additional rules.

Related Tools