Linux File Permissions Explained: chmod, chown and umask for Developers
By Álvaro G.V. · Updated
Every Linux file has three permission sets: one for its owner, one for its group and one for everyone else, each a combination of read (4), write (2) and execute (1). rwxr-xr-x is 755: the owner can do everything, everyone else can read and run. Get them wrong and you either lock yourself out or leave secrets readable by anyone on the server. This guide explains the model, the parts that surprise people (directories, umask, recursive changes) and how to debug "Permission denied".
If you'd rather click checkboxes than do octal arithmetic, the chmod calculator converts between rwxr-xr-x and 755 as you go.
The Permission Model
Every file and directory on a Linux system has three types of permissions applied to three groups of users:
| Group | Who it applies to |
|---|---|
| Owner (u) | The user who owns the file |
| Group (g) | Users who are members of the file's assigned group |
| Others (o) | Everyone else on the system |
Each group gets three independent permission bits:
- Read (r) — view the file contents / list the directory
- Write (w) — modify the file / create or delete files in the directory
- Execute (x) — run the file as a program / enter (traverse) the directory
Reading the Symbolic Notation
When you run ls -la, you see permissions in symbolic notation:
-rwxr-xr-x 1 alice devs 4096 Mar 22 deploy.sh
drwxr-xr-x 2 alice devs 4096 Mar 22 scripts/The first character is the file type (- for regular file, d for directory, l for symlink). The next 9 characters are three groups of three permission bits:
rwx r-x r-x
│ │ └── Others: read, no write, execute
│ └─────── Group: read, no write, execute
└─────────── Owner: read, write, executeUnderstanding Octal Notation
Each permission bit is a binary 1 (enabled) or 0 (disabled). The three bits in each group map to a single octal digit: read = 4, write = 2,execute = 1. Add the values of enabled bits to get the digit.
| Binary | Symbolic | Octal | Meaning |
|---|---|---|---|
| 111 | rwx | 7 | read + write + execute |
| 110 | rw- | 6 | read + write only |
| 101 | r-x | 5 | read + execute only |
| 100 | r-- | 4 | read only |
| 000 | --- | 0 | no permissions |
So chmod 755 means: owner=7 (rwx), group=5 (r-x), others=5 (r-x).
Common Permission Patterns
| Octal | Symbolic | Use case |
|---|---|---|
755 | rwxr-xr-x | Executables, binaries, shell scripts (including ones run by cron), directories |
644 | rw-r--r-- | Config files, web assets, documentation |
600 | rw------- | SSH private keys, .env files, secret credentials |
700 | rwx------ | ~/.ssh/ directory, private script directories |
664 | rw-rw-r-- | Shared files within a team group |
400 | r-------- | Immutable backups, read-only reference files |
Each of these has its own page in common chmod modes explained, for example 755, 644, 600 and the special modes 4755 (setuid) and 1777 (sticky bit).
What Permissions Mean on a Directory
On a directory the same three bits mean something different, and this is behind most confusing "Permission denied" errors:
| Bit | On a directory it allows | Without it |
|---|---|---|
r | Listing the names inside (ls) | You can still open a file if you know its exact name (given x) |
w | Creating, deleting and renaming entries (needs x too) | You can still edit existing files if the files themselves are writable |
x | Entering the directory and reaching anything below it | Nothing inside is reachable, whatever the files' own permissions are |
Two consequences worth remembering:
- Deleting a file is a directory operation. Anyone with
wandxon the directory can delete a file in it, even a read-only file they don't own. The sticky bit (as on/tmp, mode1777) is what restricts deletion to the file's owner. - Every parent directory needs
x. A web server that gets a 403 for/home/alice/site/index.htmloften fails on/home/alice(mode700), not on the file.namei -l /home/alice/site/index.htmlprints the permissions of every component of the path so you can see where traversal stops.
r without x is an odd half-state: ls lists the names, but ls -l shows ????????? for each entry because it cannot read their metadata.
chmod, chown, and chgrp
# Change permissions
chmod 755 deploy.sh # Set exact permissions (octal)
chmod u+x deploy.sh # Add execute for owner only
chmod go-w secret.conf # Remove write from group and others
chmod -R 755 /var/www/html # Recursive (use carefully)
# Change owner
chown alice deploy.sh
chown alice:devs deploy.sh # Owner and group simultaneously
# Change group
chgrp devs shared-config.ymlRecursive changes without making every file executable
chmod -R 755 dir is a common mistake: it marks every file executable, including images and config files. Directories need x; regular files usually don't. Either treat them separately:
find /var/www/html -type d -exec chmod 755 {} +
find /var/www/html -type f -exec chmod 644 {} +or use a capital X, which adds execute only to directories and to files that are already executable for someone:
chmod -R u=rwX,go=rX /var/www/htmlChecking the octal mode of a file
stat -c '%a %n' deploy.sh # Linux (GNU coreutils) → 755 deploy.sh
stat -f '%Lp %N' deploy.sh # macOS / BSD → 755 deploy.shumask: Default Permissions
umask is a mask that subtracts permissions from the default when new files and directories are created. The typical default is 022, meaning:
- New files: 666 (default) − 022 = 644 (rw-r--r--)
- New directories: 777 (default) − 022 = 755 (rwxr-xr-x)
A stricter umask like 027 would give 640 files and 750 directories — no read access for others. Set in ~/.bashrc or /etc/profile:
umask 027 # More restrictive default permissionsumask is a bit mask, not subtraction
"666 minus 022" happens to give the right answer, but the real operation is default AND NOT umask, bit by bit. The difference shows with an odd umask such as 033:
subtraction (wrong): 666 - 033 = 633 (rw--wx-wx, nonsense)
bit mask (correct): 666 & ~033 = 644 (rw-r--r--)
per digit: 6 = 110, umask 3 = 011 → 110 AND 100 = 100 = 4A umask can only remove bits. That is why new files are never executable by default, whatever the umask: the starting point for files is 666, so x has to be added with chmod +x.
Debugging "Permission denied"
| Symptom | Usual cause | Fix |
|---|---|---|
bash: ./deploy.sh: Permission denied | No execute bit, or the file system is mounted noexec (common for /tmp) | chmod u+x deploy.sh, or run it as bash deploy.sh |
WARNING: UNPROTECTED PRIVATE KEY FILE! from ssh | Key readable by group or others (e.g. 644) | chmod 600 ~/.ssh/id_ed25519 and chmod 700 ~/.ssh |
| Nginx or Apache returns 403 for a file that exists | A parent directory lacks x for the server user | Check the path with namei -l; add o+x (or the server's group) on each parent |
Script loses its execute bit after git clone | The mode was never committed (file added on Windows, or core.fileMode=false) | git update-index --chmod=+x deploy.sh, then commit |
| Container cannot write to a bind-mounted directory | The process UID inside the container doesn't own the host directory | Match the UID (--user $(id -u):$(id -g)) or chown the host directory to it |
Avoid the reflex fix of chmod 777. It makes the file or directory writable by every account on the machine, including a compromised web process, and on a directory without the sticky bit it lets anyone delete or replace what is inside.
Use the Chmod Calculator to visually build permission sets and instantly see the octal value and symbolic notation.
Frequently Asked Questions
Why does SSH refuse to use my private key and say 'permissions are too open'?▾
SSH enforces strict permissions on private keys for security. If your key file (~/.ssh/id_rsa) has permissions more permissive than 600 (rw-------), SSH will refuse to use it with an 'Unprotected private key file' error. Fix: chmod 600 ~/.ssh/id_rsa. The ~/.ssh directory itself should be 700 (drwx------). This prevents other users on the system from reading your private key.
What is setuid, setgid, and sticky bit?▾
These are three special permission bits beyond the basic rwx. setuid (s in place of owner execute): when set on an executable, it runs as the file's owner, not the user who executed it — used by /usr/bin/passwd to temporarily get root privileges. setgid (s in place of group execute): on an executable, runs as the file's group; on a directory, new files inherit the directory's group. sticky bit (t in place of other execute): on a directory, only the file owner (or root) can delete files — used on /tmp to prevent users deleting each other's temp files.
How do I find files with dangerous permissions?▾
Use find with the -perm flag. Find world-writable files: 'find / -type f -perm -002 2>/dev/null'. Find setuid binaries: 'find / -type f -perm -4000 2>/dev/null'. Find files with no owner: 'find / -nouser 2>/dev/null'. These are common security audit checks. On a production server, world-writable files or unexpected setuid binaries are red flags that warrant investigation.
Related guides
Number Systems for Developers: Binary, Octal, Decimal and Hex Explained
Why programmers use binary, octal, and hexadecimal — with practical examples from bit manipulation, color codes, file permissions, and memory addresses.
.env Files and Environment Variables Explained
Environment variables and .env files are how modern applications manage configuration across environments. Learn how they work, how to use dotenv, and how to keep secrets out of your codebase.
Cron Syntax Explained: */15 * * * * and Other Examples
Understand cron syntax with real examples. Learn how to schedule jobs with minute, hour, day, month, and weekday fields — with a handy reference table.