Linux File Permissions Explained: chmod, chown, umask and the rwx Notation

Linux 9 min readUpdated Nov 18, 2026
5 views0 comments
A rusty padlock fastened to a latch on a green wooden door
Photo: Jennifer Bourn / WordPress (CC0, public domain). source

Almost every “Permission denied” on Linux comes down to the same few rules, and once you can read them, the error stops being a mystery. This guide explains the permission string you see in ls -l, how to change it with chmod and chown, what umask does to new files, and what to check when the permissions look right but access is still refused. Examples use the Red Hat family (RHEL 9, AlmaLinux 9, Rocky Linux 9), and everything also applies to Debian and Ubuntu unless noted.

Reading the permission string

Run ls -l and every line starts with ten characters:

$ ls -l
-rw-r--r--. 1 alice developers  1204 Nov 17 09:12 report.txt
-rwxr-xr-x. 1 alice developers   310 Nov 17 09:15 backup.sh
drwxr-x---. 2 alice developers  4096 Nov 17 09:20 private

The first character is the type: - for a regular file, d for a directory, l for a symbolic link. The other nine characters are three groups of three:

Characters Who they apply to Example in -rw-r--r--
2 to 4 User (u): the owner of the file rw- owner can read and write
5 to 7 Group (g): members of the file’s group r-- group can read
8 to 10 Others (o): everyone else r-- others can read

After the permissions come the link count, the owner (alice), the group (developers), the size, the date and the name. The dot after the permissions on RHEL systems means the file has an SELinux label. You will meet SELinux again near the end of this guide.

Linux checks the three groups in order and uses the first one that matches you. If you own the file, only the owner permissions count, even if the group or others would allow more.

What r, w and x mean

Letter On a file On a directory
r read View the contents List the names inside (ls)
w write Change the contents Create, rename and delete entries inside
x execute Run it as a program or script Enter it (cd) and reach the files inside

Two consequences surprise beginners:

  • Deleting a file depends on the directory, not the file. To delete report.txt you need write permission on the directory that holds it. The file’s own permissions do not matter.
  • A directory needs x to be usable. Without it you cannot open anything inside, even a file you can read. That is why directories are normally 755 rather than 644.

The numeric (octal) notation

Each permission has a number: read = 4, write = 2, execute = 1. Add them up for each of the three groups and you get three digits:

Mode Meaning Typical use
644 rw-r--r--: owner reads and writes, everyone else reads Normal files, web pages
755 rwxr-xr-x: owner full, everyone else reads and runs Scripts, programs, directories
600 rw-------: owner only Private files, SSH private keys
700 rwx------: owner only Private directories such as ~/.ssh
664 rw-rw-r--: owner and group write Files shared by a team
775 rwxrwxr-x: owner and group full Shared team directories

To see the number for any file, use stat:

$ stat -c '%a %U:%G %n' report.txt backup.sh
644 alice:developers report.txt
755 alice:developers backup.sh

Changing permissions with chmod

chmod accepts either the number or a symbolic form. Both do the same thing, so use whichever is clearer.

chmod 644 report.txt          # set exactly rw-r--r--
chmod 755 backup.sh           # make a script runnable
chmod u+x backup.sh           # add execute for the owner only
chmod g+w,o-r report.txt      # group can write, others lose read
chmod a-w report.txt          # nobody can write (a = all)
chmod u=rw,go= secret.txt     # owner rw, group and others nothing

In the symbolic form, u, g, o and a pick who, +, - and = add, remove or set exactly, and r, w, x are the permissions.

Changing a whole tree safely

-R applies a mode recursively, but one mode for everything is usually wrong, because files and directories need different settings. The capital X helps: it adds execute only to directories (and to files that are already executable).

chmod -R u=rwX,go=rX /srv/project

Or set files and directories separately with find:

find /srv/project -type d -exec chmod 755 {} +
find /srv/project -type f -exec chmod 644 {} +

Changing the owner with chown and chgrp

Only root can give a file to another user. The owner can change the group, but only to a group they belong to.

sudo chown alice report.txt               # new owner
sudo chown alice:developers report.txt    # owner and group together
sudo chown :developers report.txt         # group only
sudo chown -R apache:apache /var/www/html/site
chgrp developers report.txt               # group only, same as chown :developers

Use -R with care. Running chown -R on the wrong path, such as / or /etc, can break a system. Check the path twice and run ls -ld on it first.

umask: the default permissions of new files

New files do not start at 777 or 666. The umask removes permissions from a starting point of 666 for files and 777 for directories.

$ umask
0022
$ touch newfile; mkdir newdir; ls -ld newfile newdir
-rw-r--r--. 1 alice alice    0 Nov 17 10:02 newfile
drwxr-xr-x. 2 alice alice 4096 Nov 17 10:02 newdir

With 022, the group and others lose write permission, so files become 644 and directories 755. Other common values:

umask New files New directories Use
022 644 755 Default for root
002 664 775 Team work where each user has a private group (the default for normal users on RHEL)
027 640 750 Others get nothing
077 600 700 Everything private

Set it for the current shell with umask 027. To make it permanent for one user, put the same line in ~/.bashrc. For a system service, set UMask=0027 in its systemd unit (see our systemd basics guide).

The special bits: setuid, setgid and sticky

A fourth digit in front of the three (for example 2775) controls three special bits:

Bit Number Effect
setuid 4 A program runs as its owner, not as whoever starts it. /usr/bin/passwd uses this so ordinary users can update the password file. It shows as s in the owner’s execute position.
setgid 2 On a directory, new files inherit the directory’s group instead of the creator’s group. Ideal for shared team folders.
sticky 1 On a directory, users can delete only their own files. /tmp uses it and shows as drwxrwxrwt.
$ ls -ld /tmp /usr/bin/passwd
drwxrwxrwt. 12 root root   260 Nov 17 10:10 /tmp
-rwsr-xr-x.  1 root root 32648 Aug 10  2021 /usr/bin/passwd

# A shared folder where everything created belongs to the group "developers"
sudo mkdir /srv/shared
sudo chgrp developers /srv/shared
sudo chmod 2775 /srv/shared

To audit setuid programs on a server, list them and make sure nothing unexpected appears:

sudo find / -xdev -type f -perm -4000 2>/dev/null

Real-world example: a website directory

A website that the web server must read but not change needs this:

sudo chown -R youruser:apache /var/www/html/site
sudo find /var/www/html/site -type d -exec chmod 750 {} +
sudo find /var/www/html/site -type f -exec chmod 640 {} +

Here the deploy user owns and edits the files, the web server’s group can read them, and everyone else gets nothing. Only the folders the application must write to (uploads, cache) should be writable by the web server.

Never use chmod 777 as a fix. It lets every account on the machine, and any compromised service, change the file. If something works only at 777, the real problem is the owner, the group, or SELinux.

When the permissions look right but you still get “Permission denied”

Work through these in order:

Check Command What to look for
Who am I, and which groups? id Your user and group names. New group membership only applies after you log out and back in.
Every folder on the path namei -l /var/www/html/site/index.html One folder without x for you blocks everything below it.
The file itself ls -l file Is your user the owner, or in the group, and does that group have the bit you need?
SELinux getenforce and ls -Z file If it says Enforcing, a wrong label can deny access even at 777.
SELinux denial log sudo ausearch -m avc -ts recent An AVC denied line that names your process and file.
Read-only mount mount | grep ' / ', findmnt -T file The ro option means nothing can be written there.

The most common SELinux fix after moving files is to restore the default label for that path:

sudo restorecon -Rv /var/www/html/site

Do not run setenforce 0 to “see if it works” and leave it that way. Use it only as a quick test, then fix the label and turn enforcement back on with setenforce 1.

Beyond rwx: ACLs in one minute

If three classes (owner, group, others) are not enough, for example when one extra person needs access to one folder, use an access control list:

sudo setfacl -m u:bob:rx /srv/project      # give bob read and enter
getfacl /srv/project                       # show the ACL
sudo setfacl -x u:bob /srv/project         # remove it again

A + after the permission string in ls -l shows that a file has an ACL.

Quick reference

Task Command
Show permissions as a number stat -c '%a %n' file
Make a script executable chmod +x script.sh or chmod 755 script.sh
Lock a private key chmod 600 ~/.ssh/id_ed25519
Change owner and group sudo chown user:group file
Fix a web folder find ... -type d -exec chmod 755 {} + and -type f ... 644
Shared group folder chgrp team dir && chmod 2775 dir
See why access fails namei -l path, ls -Z, ausearch -m avc

SSH is strict about permissions: it ignores keys that other people can read. See our guide to SSH key login for the exact modes. For the commands around this topic, the Linux commands cheat sheet is a handy companion.

Frequently asked questions

What does chmod 777 do, and why is it bad?

It gives read, write and execute permission to the owner, the group and everyone else. Any user or compromised service can then modify or replace the file. It hides the real problem (a wrong owner, group or SELinux label) and creates a security hole.

What is the difference between chmod and chown?

chmod changes what the owner, group and others may do. chown changes who the owner and group are.

Why do directories usually use 755 and files 644?

Directories need the execute bit so people can enter them, while ordinary files do not need to be executed. Both keep write access to the owner only.

Why does a new group membership not work straight away?

Group membership is read when you log in. After usermod -aG, log out and back in (or start a new session) before testing.

Can I change permissions on a file I do not own?

No. Only the owner and root can run chmod on a file. Use sudo if you are allowed to.

Did you find this helpful?Tap the heart to let us know. It takes one second and no account.

More tutorials like this

Leave a Comment

Your email address will not be published. Required fields are marked *

Bigland Network IT

Practical tutorials for people who run, build and fix things: operating systems, databases, development, networking and security.

Topics

More

Site

© 2026 Bigland Network. All rights reserved.Always test commands on a non-production system first.
Scroll to Top