Chmod Guide — File Permission Commands Explained
What Is chmod?
The chmod command changes file access permissions on Linux and Unix-like systems. Short for "change mode," it controls who can read, write, or execute a file. Every file and directory on your system has a permission mode, and chmod is the tool you use to modify it.
Without proper permissions, users cannot access files they need — or worse, can access files they should not. Understanding chmod is essential for system administration, deployment, and security.
Permission Basics
Every file has three categories of users who can access it:
- Owner — the user who created the file
- Group — users who share the file's group assignment
- Others — everyone else on the system
Each category can have three types of access:
| Permission | Symbol | Effect on Files | Effect on Directories |
|---|---|---|---|
| Read | r | View file contents | List directory contents |
| Write | w | Modify file contents | Add or remove files in directory |
| Execute | x | Run the file as a program | Enter the directory (cd into it) |
These two concepts combine to form the permission string you see in ls -l output, like rwxr-xr-x.
Numeric (Octal) Mode
The numeric mode represents permissions as a three-digit octal number. Each digit corresponds to one user category: owner, group, and others.
The digit is the sum of these values:
| Permission | Value |
|---|---|
| Read | 4 |
| Write | 2 |
| Execute | 1 |
Add the values for the permissions you want to grant. For example, read + write + execute = 4 + 2 + 1 = 7. Read + execute = 4 + 1 = 5.
Common Numeric Modes
| Mode | Permissions | Typical Use |
|---|---|---|
| 755 | rwxr-xr-x | Executable scripts, web directories |
| 644 | rw-r--r-- | Regular files, documents |
| 777 | rwxrwxrwx | Temporary shared directories (avoid in production) |
| 600 | rw------- | SSH private keys, secret config files |
| 700 | rwx------ | User-only directories |
| 640 | rw-r----- | Files shared within a group |
Numeric Examples
# Set file to 755 (rwxr-xr-x)
chmod 755 script.sh
# Set file to 644 (rw-r--r--)
chmod 644 document.txt
# Set SSH key to 600 (rw-------)
chmod 600 ~/.ssh/id_rsa
# Apply to a directory and all contents recursively
chmod -R 755 /var/www/html
Symbolic Mode
Symbolic mode uses letters to specify who gets what permission. The format is who operator permission.
Who (User Classes)
| Letter | Meaning |
|---|---|
| u | Owner (user) |
| g | Group |
| o | Others |
| a | All (same as ugo) |
Operators
| Operator | Meaning |
|---|---|
| + | Add permission |
| - | Remove permission |
| = | Set exact permission (removes others) |
Symbolic Examples
# Add execute permission for the owner
chmod u+x script.sh
# Remove write permission for group and others
chmod go-w document.txt
# Set exact permissions: owner read/write, group read, others nothing
chmod u=rw,g=r,o= document.txt
# Add read permission for everyone
chmod a+r readme.md
# Copy group permissions to others
chmod o=g file.txt
Symbolic mode is useful when you want to modify specific permissions without recalculating the full numeric value. It also makes your intent clearer in scripts.
Numeric vs Symbolic: When to Use Each
| Scenario | Recommended Mode | Reason |
|---|---|---|
| Setting exact permissions from scratch | Numeric | Unambiguous, concise |
| Modifying one permission bit | Symbolic | Avoids recalculating full mode |
| Writing deployment scripts | Numeric | Reproducible, easy to document |
| Quick one-off adjustments | Symbolic | Faster mental model |
| Copying permissions from a reference | Numeric | Direct mapping to octal |
Recursive Changes
Use the -R flag to apply permissions to a directory and everything inside it. Be careful — a blanket recursive change can break things.
# Safe: make directories executable but files read-only for group/others
find /var/www -type d -exec chmod 755 {} +
find /var/www -type f -exec chmod 644 {} +
# Dangerous: makes everything world-writable
chmod -R 777 /var/www # Do not do this in production
The find approach is the recommended way to set different permissions for files versus directories.
Practical Tips
- Always set the most restrictive permissions that allow your application to function
- A file must be readable and executable to run as a script
- A directory must be executable for users to enter it, even if they can read its listing
- Scripts with a shebang line (like
#!/bin/bash) need execute permission - Config files containing secrets should be mode 600, owned by the service account
- Web server document roots typically use 755 for directories and 644 for files
Common Mistakes
- Using 777 for convenience: This grants full access to everyone. It masks permission problems instead of solving them.
- Forgetting execute on directories: Without
x, users cannotcdinto the directory, even withrpermission. - Ignoring umask: Your umask determines default permissions for new files. Check it with
umaskbefore relying on defaults. - Recursive 777 on web roots: Attackers can overwrite any file. Use 755/644 instead.
Key Takeaways
chmodcontrols read, write, and execute access for owner, group, and others- Numeric mode uses octal values: read=4, write=2, execute=1
- Symbolic mode uses
u/g/o/a++/-/=+r/w/x - Use 755 for executables, 644 for regular files, 600 for secrets
- Always prefer the most restrictive permissions that work
- Use
findwith-type dand-type ffor safe recursive changes
Try It Yourself
Experiment with different permission combinations using our free chmod calculator. It converts between numeric and symbolic notation in real time, so you can see exactly what each mode does before running the command.
Related Guides
- Linux File Permissions Explained — deep dive into the owner/group/others model and special permission bits
- Unix Permissions Reference — quick reference for format conversion, ACLs, and web server best practices