Online admissions open for the SEO, web development and networking & cybersecurity courses. Enquire for the next batch.

Linux File Permissions: rwx, chmod, chown, umask and Special Bits

5 min read Updated By the SkillNewton team

How do Linux file permissions work?

Linux file permissions control who can read, write and execute each file and directory. Every file has an owner and a group, and three permission sets apply to the owner, the group and everyone else. You view them with ls -l, change them with chmod, change ownership with chown or chgrp, and set defaults for new files with umask.

Reading the output of ls -l

$ ls -l
-rw-r-----  1 alice  finance  2048 Nov 10 09:15 budget.xlsx
drwxr-x---  2 alice  finance  4096 Nov 10 09:10 reports
-rwxr-xr-x  1 root   root     8192 Nov  9 18:02 backup.sh

The first character is the file type: - for a regular file, d for a directory and l for a symbolic link. The next nine characters are three groups of three: the user (owner), the group and others. Then come the link count, owner name, group name, size, modification time and name.

So -rw-r----- on budget.xlsx means alice can read and write, members of the finance group can read, and nobody else has any access. A + after the nine characters means the file also has an access control list, which you can view with getfacl.

What r, w and x mean on files and directories

PermissionOn a fileOn a directory
r (read)Read the contentsList the names inside it
w (write)Change the contentsCreate, delete and rename entries inside it (needs x too)
x (execute)Run it as a program or scriptEnter it with cd and reach files inside it

The directory rules surprise many learners. Deleting a file depends on write permission on the directory, not on the file. A directory with r but no x lets you see names but not open anything. The root user bypasses these checks, which is one reason to avoid working as root, as explained in Linux for network engineers.

Numeric (octal) chmod

Each permission has a value: read is 4, write is 2 and execute is 1. Add them for each of user, group and others to get three digits.

ModeStringTypical use
644rw-r--r--Ordinary files, web pages
640rw-r-----Files shared with a group only
600rw-------Private keys, files with credentials
755rwxr-xr-xDirectories, scripts and programs
750rwxr-x---Directories for one team
700rwx------A private directory such as ~/.ssh
chmod 640 budget.xlsx
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519

Symbolic chmod, chown and chgrp

Symbolic mode changes individual bits without retyping the rest. Use u, g, o or a (all), then + to add, - to remove or = to set exactly.

chmod u+x deploy.sh             # owner may execute
chmod g-w shared.txt            # group may no longer write
chmod o= private.txt            # remove all access for others
chmod u=rw,g=r,o= notes.txt     # same as 640
chmod -R g+rX projects/         # group read; X adds execute only to directories
                                # (and files already executable)

sudo chown bob report.txt              # change owner
sudo chown bob:finance report.txt      # change owner and group
sudo chgrp finance report.txt          # change group only
sudo chown -R www-data:www-data /var/www/site

Only root can give a file to another user. An owner can change the group to one they belong to. Use -R carefully: a recursive change on the wrong path can break a system or expose data.

umask: default permissions for new files

New files start from 666 and new directories from 777. The umask lists the bits to remove. With the common umask 022, new files become 644 and new directories 755. A stricter umask of 027 gives 640 and 750, so others get nothing.

umask          # show the current value, for example 0022
umask 027      # set it for this shell session

To make a change permanent for your account, add the umask line to your shell start-up file such as ~/.bashrc. System-wide defaults are set in files such as /etc/login.defs, depending on the distribution. Services started by systemd use the UMask= setting in their unit files.

setuid, setgid and the sticky bit

BitOctalShows asEffect
setuid4000s in the user execute positionA program runs with the privileges of the file owner, as /usr/bin/passwd does to update password data
setgid2000s in the group execute positionOn a directory, new files inherit the directory group; on a program, it runs with the file group
sticky1000t in the others execute positionOn a directory, users can delete only their own files, as in /tmp
$ ls -ld /tmp /usr/bin/passwd
drwxrwxrwt 18 root root  4096 Nov 10 09:00 /tmp
-rwsr-xr-x  1 root root 68248 Nov  1 12:00 /usr/bin/passwd

sudo chmod 2775 /srv/shared            # setgid shared team directory
sudo find / -perm -4000 -type f 2>/dev/null   # list setuid programs

A capital S or T means the special bit is set but the matching execute bit is not, which is usually a mistake. Setuid programs owned by root are a classic route to privilege escalation, so security audits list them and compare against a known baseline, as covered in security auditing. Linux ignores setuid on shell scripts.

Practical exercise: set up a shared team directory

On a Linux virtual machine you own, with sudo access:

  1. Create a group labteam and two users, and add both users to the group.
  2. Create /srv/labteam, set its group to labteam and its mode to 2770.
  3. As each user, create a file inside it and confirm with ls -l that the group is labteam.
  4. Set the umask to 007 in a shell and create another file; confirm group members can edit it.
  5. Add the sticky bit with chmod +t and confirm one user can no longer delete a file owned by the other.
  6. Confirm a third user outside the group cannot list the directory.

You are done when every check behaves as expected and you can explain each permission string you see. More system administration practice is in the Networking Foundation course, and everyday shell tools are in essential Linux commands.

Common mistakes

  • Running chmod 777 to fix an access error, which lets every user change or replace the file.
  • Running chmod -R 755 on a tree of files, which makes every data file executable.
  • Removing execute from a directory and then wondering why nobody can open files inside it.
  • Leaving private keys or configuration files with passwords readable by others.
  • Setting the setuid bit on a program without understanding that it runs with the privileges of its owner.

Frequently asked questions

Why can I not delete a file even though I own it?

Deleting needs write and execute permission on the directory that holds the file. If the directory also has the sticky bit, only the file owner, the directory owner or root can delete it.

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.

When should I use ACLs instead of normal permissions?

Use access control lists when one file needs different access for several specific users or groups, which owner, group and others cannot express. Set them with setfacl -m u:bob:r file and view them with getfacl.

Want to Learn This Properly?

The Networking & Cybersecurity: Foundation & Practical Implementation (Online) turns guides like this into practised skills, with projects on real websites.

WhatsApp Call Us Now

Free counselling

Send an Enquiry

Tell us which course you are interested in. We reply by email or phone with the next batch and how to enrol.

Protected by reCAPTCHA. Google Privacy and Terms apply.

We reply by email or phone within working hours. No spam.