Managing File and Directory Permissions with chmod in Linux

Understanding Linux Permission Model

In Linux/Unix systems, file and directory access is controlled through a three-tier permission structure:

  • Owner (User): The individual who owns the file
  • Group: Users belonging to the file's associated group
  • Others: All remaining users on the system

To examine current permissions, use the ls -l command which displays detailed information in long format:

ls -l

Example output:

drwxr-xr-x  4 root root    4096 Feb  10  2021 speech-dispatcher
-rw-r--r--  1 root root      20 Jan   4  2022 subgid
-rw-r--r--  1 root root       0 Feb  10  2021 subgid-
-r--r-----  1 root root     755 Feb   3  2020 sudoers
drwxr-xr-x  3 root root  4096 Nov  10  2023 sudoers.d

Permission String Breakdown

The first 10 characters represent the permission bits:

  1. File type: First character indicates type

    • d — directory
    • - — regular file
    • l — symbolic link
    • Other types exist but are less common
  2. Permission sets: Characters 2-10 are divided into three groups of three, representing owner (u), group (g), and others (o):

    • r (Read): View file contents or list directory entries
    • w (Write): Modify file contents or create/delete files within a directory
    • x (Execute): Run a file as a program or traverse a directory
    • - : Permission denied

Numeric (Octal) Notation

Each permission type corresponds to a bit value:

Permission Binary Decimal
r 100 4
w 010 2
x 001 1

Combine values for each category (owner, group, others) to form a three-digit octal number:

chmod 755 /path/to/script.sh    # Owner: rwx (7), Group: r-x (5), Others: r-x (5)
chmod 644 /var/data/config.txt  # Owner: rw- (6), Group: r-- (4), Others: r-- (4)
chmod 600 /home/user/.ssh/key   # Owner: rw- (6), Group: --- (0), Others: --- (0)

chmod Command Options

chmod [options] mode file_or_directory
Option Description
-c Report only when changes are made
-f Suppress error messages
-v Output diagnostic for every processed file
-R Apply changes recursively to directories and their contents
--help Display help information
--version Show version details

Symbolic Notation

Symbolic notation provides more granular control using letters and operators:

Target Identifiers

Symbol Meaning
u Owner/User
g Group
o Others
a All (equivalent to ugo)

Operators

Operator Action
+ Add specified permissions
- Remove specified permissions
= Set permissions exactly, clearing unspecified ones

Permission Modes

Symbol Description
r Read access
w Write access
x Execute access
X Conditional execute — sets x only if the target is a directory or another user already has execute permission
s Set UID/GID bit — executes with owner or group permissions
t Sticky bit — restricts deletion to file owner (useful for shared directories)

Syntax

chmod [who][operator][permissions] target

Practical Examples

# Grant write access to the file owner
chmod u+w data.txt

# Remove execute permission from owner, add read to group
chmod u-x,g+r executable.sh

# Assign read-write to everyone
chmod a=rw notes.md

# Make a script executable for all users
chmod +x install.sh

# Set directory so only owner can delete files inside it
chmod +t /shared/folder

# Recursively set directory permissions
chmod -R 755 /var/www/html

Common Permission Patterns

Octal Symbolic Use Case
777 rwxrwxrwx Full access for every one (use sparing)
755 rwxr-xr-x Executables, public directories
644 rw-r--r-- Regular files, readable by all
600 rw------- Private files, owner-only access
700 rwx------ Private directories
2755 rwxr-sr-x Executable with group ID set
1777 rwxrwxrwt Shared temp directory with sticky bit

Tags: Linux chmod permissions file-system command-line

Posted on Thu, 27 Aug 2026 16:02:06 +0000 by sone_br