Linux File Permissions: A Practical chmod and chown Guide
One of the easiest Linux commands to memorize is chmod.
One of the easiest Linux commands to misuse is also chmod.
When an application cannot read a file or a script refuses to execute, changing everything to 777 might seem convenient. However, it creates an unnecessarily broad access policy.
Understanding permissions makes troubleshooting much easier.
Reading Linux permissions
Start with:
ls -l
Consider this example:
-rw-r----- 1 www-data adm 1024 Nov 22 access.log
The first character describes the object type. The next nine characters contain three permission groups:
- Owner: rw-
- Group: r--
- Others: ---
The owner can read and modify the file. Members of the assigned group can read it. Other ordinary users receive no access.
Understanding permission numbers
Linux uses three basic permission values:
| Permission | Symbol | Value |
|---|---|---|
| Read | r | 4 |
| Write | w | 2 |
| Execute | x | 1 |
Combining them produces common modes:
- 7 = rwx
- 6 = rw-
- 5 = r-x
- 4 = r--
- 0 = ---
Therefore, 755 means full access for the owner and read/execute permissions for group and others.
A small hands-on exercise
Run this in a disposable practice directory:
lab=$(mktemp -d)
cd "$lab" || exit
touch example.txt
chmod 644 example.txt
ls -l example.txt
chmod 600 example.txt
ls -l example.txt
Notice how the group and others lose their read access when you change from 644 to 600.
Symbolic chmod
You don't always need numeric modes.
chmod u+x script.sh
chmod g+w shared.txt
chmod o-r private.txt
Here, u represents the owner, g represents the group and o represents others.
Symbolic changes are useful when you want to adjust specific bits instead of replacing an entire permission mode.
The files in these examples must already exist.
Ownership with chown
Permissions only make sense when you know who owns the file.
The following is an illustrative command for an existing deployment user and group:
sudo chown deploy:devops application.conf
Unlike chmod, chown changes ownership.
Always verify the intended account and group before changing production ownership.
Files and directories behave differently
Execute permission on a regular file allows execution, subject to additional system restrictions.
On directories, execute permission allows traversal.
This is why an application may have read permission on a configuration file but still be unable to access it.
A useful Linux diagnostic command is:
namei -l /path/to/application.conf
It displays permissions for the components of a path.
Special permission bits
Linux has three additional permission bits.
- SUID can change the effective user ID during eligible executable execution.
- SGID on directories enables group inheritance for new entries.
- The sticky bit limits deletion and renaming in shared writable directories.
You can inspect a familiar sticky-bit example:
ls -ld /tmp
Look for the final t in the permissions.
How umask works
Umask removes permission bits from the mode requested by a process.
For typical file and directory creation:
| Umask | File mode | Directory mode |
|---|---|---|
| 022 | 644 | 755 |
| 027 | 640 | 750 |
| 077 | 600 | 700 |
The underlying calculation uses bitwise masking, not ordinary arithmetic subtraction.
Production considerations
For SSH credentials, private keys commonly need mode 600.
For web applications, keep application code protected from unnecessary writes by the runtime account.
For Kubernetes persistent volumes, verify the container UID, GID and storage driver's support for fsGroup before changing filesystem permissions.
Final thoughts
Linux permissions are not complicated once ownership and permission bits become part of your troubleshooting process.
Inspect first. Identify the required access. Make the smallest necessary change.
For the extended production hardening guide, interactive exercises and Kubernetes examples, read the original Linux file permissions article.
Further reference: GNU Coreutils chmod documentation.
Top comments (0)