DEVESSENTIALS

Linux File Permissions Explained: chmod, chown and umask for Developers

By · 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:

GroupWho 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, execute

Understanding 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.

BinarySymbolicOctalMeaning
111rwx7read + write + execute
110rw-6read + write only
101r-x5read + execute only
100r--4read only
000---0no permissions

So chmod 755 means: owner=7 (rwx), group=5 (r-x), others=5 (r-x).

Common Permission Patterns

OctalSymbolicUse case
755rwxr-xr-xExecutables, binaries, shell scripts (including ones run by cron), directories
644rw-r--r--Config files, web assets, documentation
600rw-------SSH private keys, .env files, secret credentials
700rwx------~/.ssh/ directory, private script directories
664rw-rw-r--Shared files within a team group
400r--------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:

BitOn a directory it allowsWithout it
rListing the names inside (ls)You can still open a file if you know its exact name (given x)
wCreating, deleting and renaming entries (needs x too)You can still edit existing files if the files themselves are writable
xEntering the directory and reaching anything below itNothing inside is reachable, whatever the files' own permissions are

Two consequences worth remembering:

  • Deleting a file is a directory operation. Anyone with w and x on the directory can delete a file in it, even a read-only file they don't own. The sticky bit (as on /tmp, mode 1777) 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.html often fails on /home/alice (mode 700), not on the file. namei -l /home/alice/site/index.html prints 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.yml

Recursive 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/html

Checking 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.sh

umask: 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 permissions

umask 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 = 4

A 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"

SymptomUsual causeFix
bash: ./deploy.sh: Permission deniedNo 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 sshKey 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 existsA parent directory lacks x for the server userCheck the path with namei -l; add o+x (or the server's group) on each parent
Script loses its execute bit after git cloneThe 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 directoryThe process UID inside the container doesn't own the host directoryMatch 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.

Browse all developer guides →