Linux File Permissions Explained: rwx, chmod, chown, umask and SUID

Every Linux file and directory has an owner, a group and three sets of permissions: read (r), write (w) and execute (x) for the owner, the group and everyone else. You change them with chmod, using numbers where r=4, w=2 and x=1 (so 644 is rw-r--r--), or symbols such as u+x. chown changes the owner and group, and umask sets the defaults for new files.

Apr 08, 2025 - 14:05
Updated: 
106.2k

Linux Administration in IT Infrastructure · Explainer

Linux to RHCSA, lesson 4 of 23

Linux File Permissions Explained: rwx, chmod, chown, umask and SUID

Quick answer: Every Linux file and directory has an owner, a group and three sets of permissions: read (r), write (w) and execute (x) for the owner, the group and everyone else. You change them with chmod, using numbers where r=4, w=2 and x=1 (so 644 is rw-r--r--), or symbols such as u+x. chown changes the owner and group, and umask sets the defaults for new files. Three special bits, SUID, SGID and the sticky bit, change how programs run and how shared folders behave. Avoid chmod 777; it lets anyone change the file.

Key takeaways

  • Permissions apply separately to the owner, the group and others.
  • On directories, x means enter and r means list.
  • Numeric modes add 4, 2 and 1 for each class.
  • umask removes permissions from new files; 022 is a typical default.
  • SUID root programs and world-writable files are common audit findings.

Table of Contents

What Do r, w and x Mean?

PermissionOn a fileOn a directory
r (4)Read contentsList names inside
w (2)Change contentsCreate, delete or rename entries (needs x too)
x (1)Run as a programEnter and access items inside

Deleting a file depends on write permission on its directory, not on the file itself. That surprises many beginners.

How Do You Read ls -l Output?

ls -l report.txt
-rw-r----- 1 alice finance 2048 Nov 14 10:00 report.txt
stat -c '%A %a %U %G %n' report.txt
-rw-r----- 640 alice finance report.txt

The first character is the type (- file, d directory, l link). The next nine are three groups of rwx for owner, group and others. Here alice can read and write, the finance group can read, and others have no access.

How Does Numeric chmod Work?

ModeSymbolicTypical use
600rw-------Private files, SSH private keys
640rw-r-----Config readable by a service group
644rw-r--r--Ordinary files and web content
700rwx------Private directories and scripts
755rwxr-xr-xPrograms and shared directories
777rwxrwxrwxAlmost never; anyone can modify

Add the values per class: rw- is 4+2=6, r-x is 4+1=5. So chmod 640 file gives the owner read and write, the group read, and others nothing, as described in chmod(1).

How Does Symbolic chmod Work?

chmod u+x deploy.sh        # add execute for the owner
chmod g-w shared.txt       # remove write from the group
chmod o= notes.txt         # remove all access for others
chmod a+r readme.txt       # everyone may read
chmod -R u=rwX,go=rX docs  # X sets execute on directories only, unless a file is already executable

Symbolic mode changes only what you name, which is safer than replacing the whole mode. Be careful with -R; test on a copy first.

How Do chown and umask Work?

chown changes ownership and needs root for most uses: sudo chown alice:finance report.txt. chgrp changes only the group. umask removes bits from the default mode of new files. According to umask(2), a typical default is 022, so a file created with 666 becomes 644 and a directory created with 777 becomes 755. A stricter umask of 027 gives 640 and 750. Run umask to see yours. For finer control than owner, group and others, use access control lists with setfacl and getfacl.

What Are SUID, SGID and the Sticky Bit?

BitOctalEffectRisk
SUID4000Program runs with the file owner's rights (s in owner x)A flawed SUID root program can give root access
SGID2000Program runs with the group's rights; on directories, new files inherit the groupUnexpected group access
Sticky1000In a shared directory, only owners can delete or rename their files (t in others x)Missing on world-writable dirs lets users delete others' files

/usr/bin/passwd is SUID root so users can update their own password, and /tmp normally has mode 1777. The inode(7) page defines these bits, and execve(2) notes that Linux ignores SUID and SGID on interpreted scripts. Attackers look for misconfigured SUID binaries, which MITRE tracks as Setuid and Setgid (T1548.001).

How Do You Audit Risky Permissions?

These read-only find commands list files that deserve review on your own systems:

# SUID and SGID files on the root filesystem
sudo find / -xdev -type f \( -perm -4000 -o -perm -2000 \) -ls 2>/dev/null
# World-writable files
sudo find / -xdev -type f -perm -0002 -ls 2>/dev/null
# World-writable directories without the sticky bit
sudo find / -xdev -type d -perm -0002 ! -perm -1000 -ls 2>/dev/null

Compare results with a known-good baseline, remove SUID from programs that do not need it, mount removable and temporary filesystems with nosuid where practical, and follow the least-privilege advice in NIST SP 800-123. For users, groups and sudo, see our sibling guide on controlling access on Linux, and for everyday commands our Linux command reference. WebAsha runs hands-on Linux administration and security training.

References

Frequently Asked Questions

The owner can read, write and execute, while the group and others can read and execute but not change the file or directory.

It gives every user write access, so anyone on the system can change or replace the file, including scripts that other users or services run.

chmod changes the permission bits on a file, while chown changes which user and group own it; chown usually requires root.

It removes write permission for group and others from new files, so files usually get 644 and directories get 755.

SUID makes a program run with the rights of the file’s owner, often root, which is useful for tools like passwd but risky if misused.

It lets everyone create files in /tmp but allows only each file’s owner, the directory owner or root to delete or rename it.

No. On a directory, execute means you may enter it and access files inside, while read lets you list the names it contains.

Run sudo find / -xdev -type f -perm -4000 -ls and compare the results against a known-good list for your distribution.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Vaishnavi

Vaishnavi is a skilled tech professional at the Ethical Hacking Training Institute in Pune, responsible for managing and optimizing the technical infrastructure that supports advanced cybersecurity education. With deep expertise in network security, backend operations, and system performance, she ensures that practical labs, online modules, and assessments run smoothly and securely. Her behind-the-scenes contributions play a vital role in delivering a seamless and secure learning experience for aspiring ethical hackers.