Home › Guides › Developer › Linux file permissions and chmod explained

Linux file permissions and chmod explained

Understand read, write and execute bits, octal modes such as 755 and 644, directories, special bits and umask, with worked examples.

By the tools4free.dev team · Last reviewed 4 December 2026

Every file on a Linux or other POSIX system has three sets of permission bits: one for the owner, one for the owning group and one for everyone else. Each set can allow read, write and execute. chmod changes those bits, and you can write them as a three-digit octal number such as 755 or as symbolic text such as u+x.

Reading the output of ls -l

Run ls -l and the first column shows ten characters:

-rwxr-xr-- 1 alice devs 2048 Dec  4 09:30 deploy.sh
drwxr-x--- 2 alice devs 4096 Dec  4 09:12 reports

The first character is the file type: - for a regular file, d for a directory, l for a symbolic link. The next nine characters are three groups of three, in the order owner, group, others. In deploy.sh, the owner alice has rwx (read, write, execute), members of devs have r-x (read and execute), and everyone else has r-- (read only).

How the octal numbers work

Each permission has a value: read is 4, write is 2 and execute is 1. You add the values for each class to get one digit. Three classes give three digits.

DigitBinarySymbolsMeaning
0000---No access
1001--xExecute only
2010-w-Write only
3011-wxWrite and execute
4100r--Read only
5101r-xRead and execute
6110rw-Read and write
7111rwxFull access

So 754 is owner 7 (4+2+1, rwx), group 5 (4+1, r-x) and others 4 (r--), which is exactly the -rwxr-xr-- shown above.

Worked example 1: making a script runnable

You have just copied a shell script onto a server and need to run it.

$ ls -l backup.sh
-rw-r--r-- 1 alice alice 312 Dec  4 10:00 backup.sh

$ ./backup.sh
bash: ./backup.sh: Permission denied

$ chmod u+x backup.sh
$ ls -l backup.sh
-rwxr--r-- 1 alice alice 312 Dec  4 10:00 backup.sh

$ chmod 755 backup.sh
$ ls -l backup.sh
-rwxr-xr-x 1 alice alice 312 Dec  4 10:00 backup.sh

The file started at 644 (rw-r--r--), which has no execute bit, so the shell refused. u+x added execute for the owner only. 755 then set the exact result in one step: owner rwx, group and others r-x. Use u+x when you want to change one thing and keep the rest; use the number when you want a known final state.

Symbolic mode

Symbolic mode has three parts: who (u owner, g group, o others, a all), an operator (+ add, - remove, = set exactly) and the permissions (r, w, x). You can combine clauses with commas.

chmod g+w notes.txt          # let the group write
chmod o-rwx secrets.env      # remove all access for others
chmod a+r readme.txt         # everyone can read
chmod u=rwx,g=rx,o= tool     # same as 750
chmod -R u+rwX,go+rX site/   # capital X: see below

The capital X means "set execute only if the item is a directory or already has execute for someone". It is the safe way to fix a whole tree, because it opens directories without making every data file executable.

Directories are different

The three bits mean something else on a directory:

A directory with r-- and no x is a trap: you can see the file names but cannot open any file or read its details. That is why directories are normally 755 or 750, never 644. Deleting a file depends on the permissions of the directory that contains it, not on the file's own permissions.

Worked example 2: a shared project folder

A team in the group devs needs to share /srv/project. Everyone in the group should create and edit files, and other users should have no access. New files should belong to the group, not to whichever user created them.

sudo chgrp -R devs /srv/project
sudo chmod -R u+rwX,g+rwX,o-rwx /srv/project
sudo chmod g+s /srv/project

The last command sets the setgid bit on the directory. Files created inside then inherit the group devs. The directory shows as drwxrws---: the lowercase s in the group execute position means setgid is on and execute is also on. In octal that directory is 2770.

Special bits: setuid, setgid and sticky

A fourth, leading octal digit holds three special bits.

BitValueOn a fileOn a directory
setuid4000Runs with the file owner's user IDIgnored on Linux
setgid2000Runs with the file's group IDNew files inherit the directory's group
sticky1000Historically ignored on filesOnly a file's owner (or the directory owner or root) can delete or rename it

The classic examples are /usr/bin/passwd, which is setuid root so ordinary users can update their password entry (-rwsr-xr-x, mode 4755), and /tmp, which is 1777 and shown as drwxrwxrwt. Everyone can create files in /tmp, but the sticky bit stops them deleting each other's files.

umask: the default permissions

New files start from 666 and new directories from 777, then the process's umask removes bits. With the common umask 022, a new file is 644 and a new directory is 755. With 027, a new file is 640 and a new directory is 750. With 077, new files are 600 and directories 700. Files are not created executable by default, which is why scripts need an explicit chmod.

Common mistakes

Frequently asked questions

What does chmod 644 mean?

Owner can read and write (6), group can read (4) and others can read (4). It is the usual mode for ordinary files.

What is the difference between 755 and 775?

The only change is the group digit: 5 is read and execute, 7 adds write. Use 775 when a group needs to modify the contents of a directory.

Does root ignore permissions?

Mostly. Root can read and write any file regardless of the mode bits, but still needs at least one execute bit set to run a regular file as a program.

How do I see the octal value of a file?

Run stat -c '%a %n' file with GNU coreutils. On macOS or BSD use stat -f '%Lp %N' file.

Try it: tick boxes and see the octal and symbolic result in the chmod calculator.

Sources