How to Set and Modify File Permissions in Linux

Set Linux file permissions with chmod symbolic and octal modes, chown, special bits, umask and ACLs, plus a fix list for permission denied.

Aug 1, 2025 - 17:38
Nov 14, 2026 - 15:05
 0  33
How to Set and Modify File Permissions in Linux

You set and modify file permissions in Linux with chmod, which changes read, write and execute bits for the owner, group and others, and chown, which changes who owns a file. Permissions can be written as letters (u+x) or octal numbers (755). umask controls defaults for new files, and ACLs add per-user rules.

Key takeaways

  • Every file has an owner, a group and three permission sets: owner, group and others. Each set has read (4), write (2) and execute (1).
  • chmod accepts symbolic modes such as u+x,go-w and numeric modes such as 640. A fourth leading digit sets setuid (4), setgid (2) and the sticky bit (1).
  • chown user:group file changes owner and group together; chown :group file changes only the group.
  • The capital X in symbolic mode adds execute only to directories and files that are already executable for someone, which makes recursive changes safe.
  • The umask removes bits from the mode a program requests. With the common umask 022, a file requested as 0666 is created as 0644.
  • When three permission sets are not enough, setfacl grants rights to named users and groups, limited by the ACL mask.

How Linux decides who can do what

Linux attaches an owner and a group to every file and directory, plus a mode. When a process tries to open a file, the kernel checks the process's user ID. If it matches the owner, the owner bits apply. If not, and one of the process's groups matches the file's group, the group bits apply. Otherwise the "other" bits apply. Only one set is used. A common surprise follows from this: if the owner bits are stricter than the group bits, the owner gets the stricter set, even though they are also in the group.

If you are new to the command line, our guide to RHEL 10 basic commands covers navigation and file handling first. Everything in this article works the same way on RHEL, Ubuntu, Debian and other distributions that ship GNU coreutils.

Reading the output of ls -l

$ ls -l deploy.sh
-rwxr-x--- 1 asha devops 2048 Nov 12 10:15 deploy.sh

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. Here the owner asha has rwx, members of the group devops have r-x, and everyone else has nothing.

What r, w and x mean on files and directories

BitOn a fileOn a directory
r (4)Read the contentsList the names inside
w (2)Change the contentsCreate, delete or rename entries (needs x too)
x (1)Run it as a program or scriptEnter it and reach files inside by name

The directory row trips up beginners more than anything else. Deleting a file is an operation on the directory that contains it, not on the file itself. A user with write and execute on a directory can delete a file in it even if the file is read-only to them. That is exactly the problem the sticky bit solves, covered further down.

Changing permissions with chmod

Symbolic mode

Symbolic mode describes a change. The GNU coreutils manual gives the form as one or more of u, g, o or a (user, group, others, all), an operator, and permission letters. + adds bits, - removes them and = sets them exactly. Several clauses can be joined with commas.

chmod u+x deploy.sh          # owner may execute
chmod go-w config.yaml       # remove write from group and others
chmod u=rw,g=r,o= secrets.env   # exact: rw for owner, r for group, nothing for others
chmod a+r README.md          # everyone may read

If you leave out the user letters, a is assumed, but the manual notes that bits set in your umask are then left alone. So chmod +w file under a 022 umask adds write for the owner only. That behaviour is easy to forget; naming the target explicitly avoids it.

Symbolic mode is the better choice when you want to change one thing and leave the rest as it is. Adding execute to a script without touching its read and write bits is a single u+x.

Numeric (octal) mode

Numeric mode sets the whole mode at once. Each digit is the sum of read (4), write (2) and execute (1) for owner, group and others in that order.

ModeLettersTypical use
755rwxr-xr-xDirectories and programs everyone may run
750rwxr-x---Scripts shared within a team group
644rw-r--r--Ordinary readable files
640rw-r-----Config files readable by a service group
600rw-------Private keys and credential files
700rwx------A user's private directory, such as ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 700 ~/.ssh
chmod 640 /etc/myapp/app.conf

Numeric mode is clearer in scripts and automation, because the result does not depend on what the mode was before. A provisioning script that runs chmod 640 always ends at the same state, which is what configuration management tools want.

Recursive changes and the capital X

chmod -R applies a mode to a directory and everything beneath it. Combined with a numeric mode it is a blunt tool: chmod -R 755 project/ marks every text file executable, which is untidy and sometimes a security problem. The coreutils manual describes a better option. The capital X grants execute or search permission only if the target is a directory or already has execute permission for some user.

chmod -R u=rwX,g=rX,o= project/

That one line gives directories rwxr-x--- so people can enter them, and gives ordinary files rw-r-----, while scripts that were already executable stay executable. The manual also notes that during a recursive walk, chmod ignores symbolic links it encounters, so you do not accidentally change files outside the tree through a link.

Changing ownership with chown and chgrp

Permissions only make sense in relation to an owner and a group, so changing ownership is half the job. chown takes an owner, an optional group, and the files.

sudo chown asha deploy.sh              # owner only
sudo chown asha:devops deploy.sh       # owner and group
sudo chown asha: deploy.sh             # owner, and group set to asha's login group
sudo chown :devops deploy.sh           # group only, same as chgrp devops deploy.sh
sudo chown -R www-data:www-data /var/www/site
sudo chown --reference=app.conf new.conf   # copy owner and group from another file

There must be no spaces around the colon. Changing the owner of a file normally requires root, which is why these commands usually run with sudo. If you manage who may run privileged commands, our post on securing sudo access covers that side.

A practical pattern for shared team directories is to create a group, add the right users to it, make the group own the directory, and give the group write access. That keeps "others" locked out without making everything belong to one person.

Special bits: setuid, setgid and sticky

The optional leading digit in numeric mode controls three special bits. The coreutils manual lists 4 for setuid, 2 for setgid and 1 for the sticky bit (also called the restricted deletion flag). In symbolic mode they appear as s and t.

Setuid (4)

On an executable, setuid makes the program run with the file owner's user ID rather than the caller's. It is how certain system programs perform privileged work on behalf of ordinary users. It is also a common target during security audits, because a careless setuid program owned by root gives too much power. Avoid setting it on your own scripts and review the list of setuid files on servers regularly with find / -perm -4000 -type f.

Setgid (2)

On a directory, setgid is genuinely useful for teams: new files created inside inherit the directory's group rather than the creator's primary group. Combined with group write permission it keeps a shared folder consistently owned.

sudo chgrp devops /srv/shared
sudo chmod 2775 /srv/shared

The manual notes a subtlety: for directories, chmod preserves existing setuid and setgid bits unless you say otherwise. To clear them with a numeric mode you need a leading zero such as 00755, a leading minus such as -6000, or an equals form such as =755.

Sticky bit (1)

On a directory, the sticky bit stops unprivileged users from removing or renaming files they do not own, even when the directory is writable by everyone. /tmp is the classic example. Use it on any shared drop folder where many users write files.

chmod 1777 /srv/dropbox
ls -ld /srv/dropbox
drwxrwxrwt 2 root root 4096 Nov 12 10:30 /srv/dropbox

The trailing t in place of the last x shows the sticky bit is set.

Default permissions with umask

When a program creates a file, it asks the kernel for a mode, and the kernel removes any bits that are set in the process's umask. The Linux man page puts it as "permissions in the umask are turned off from the mode argument". The result is roughly mode & ~umask. With the typical umask of 022, a file requested with 0666 is created as 0644, and a directory requested with 0777 becomes 0755.

umask          # show the current mask, for example 0022
umask 027      # new files 640, new directories 750 in this shell

A stricter umask such as 027 is common on servers, because it keeps new files out of reach of "others" by default. Set it in the service's unit file or the user's shell profile rather than system-wide unless you have tested the effect. One more detail from the man page: if the parent directory has a default ACL, the umask is ignored and the new file's permissions come from that ACL.

Access control lists for finer control

Owner, group and others cover most needs, but not all. Suppose a log directory belongs to the app group and an auditor account needs read access without joining that group. That is where POSIX ACLs help.

setfacl -m u:auditor:rx /var/log/myapp        # grant a named user read and execute
setfacl -d -m u:auditor:r /var/log/myapp      # default ACL so new files inherit it
getfacl /var/log/myapp                         # inspect entries
setfacl -x u:auditor /var/log/myapp            # remove that entry
setfacl -b /var/log/myapp                      # remove all extended entries

The setfacl man page explains the mask entry, which is easy to overlook. The mask is the ceiling on effective rights for named users, named groups and the owning group. If you later run a chmod that lowers the group bits, the mask drops too and your ACL entries may grant less than they appear to. Read the mask line in the getfacl output whenever access looks wrong. When ls -l shows a + after the mode, the file has an ACL, so always check with getfacl before assuming the nine bits tell the whole story.

Security habits worth building

Start from the least access that works. Configuration files with credentials should be 600 or 640 with a dedicated group, never world-readable. Avoid chmod 777 as a fix for "permission denied" errors. It works by removing every protection, and the real cause is almost always the wrong owner or a missing group membership.

Remember that permissions are one layer. On RHEL and Fedora systems, SELinux applies a second check, so a file can have correct mode bits and still be blocked. Our article on SELinux in RHEL 10 explains how to read those denials. Password hashes in /etc/shadow are a good example of a file that depends on strict permissions, covered in our post on the /etc/shadow file.

Finally, audit. find can list world-writable files (find / -xdev -type f -perm -0002), setuid files and files owned by users who no longer exist. Running those checks on a schedule catches drift that slips in through manual fixes.

Troubleshooting "Permission denied"

When a command fails with "Permission denied", work through the same short checklist every time instead of reaching for chmod 777.

  1. Check who you are. Run id to see your user ID and every group you belong to. Group membership added a minute ago does not apply to a shell that was already open; log in again or start a new session.
  2. Check the file. Run ls -l on it and work out which of the three sets applies to you: owner, group or others. Remember that only one set is used.
  3. Check every directory on the path. You need execute permission on each parent directory to reach a file, even if the file itself is world-readable. namei -l /path/to/file prints the owner and mode of each component in one go, which makes a missing x on a parent easy to spot.
  4. Check for an ACL. A + after the mode in ls -l means extended entries exist. Run getfacl and read the mask line.
  5. Check the security layer. On SELinux systems, a file with correct mode bits can still be denied because of its label. Look in the audit log before changing permissions.
  6. Check the filesystem. A filesystem mounted read-only, or with options that block execution, will refuse writes or program runs regardless of mode bits.

Most real cases end at step 2 or 3: the file belongs to the wrong user after being copied with sudo, or a parent directory is 700. Fixing ownership with chown or adding the user to the right group solves the problem without opening the file to everyone. Write down the cause when you fix it. Repeated permission issues on the same path usually point to a deployment step that creates files as the wrong user, and that is better fixed once in the pipeline than by hand on every server.

Where this shows up in certification and work

File permissions are part of the "file systems" objectives of the Red Hat EX200 exam for RHCSA, which Red Hat states is based on RHEL 10, and they come up in nearly every Linux and DevOps interview. Our RHCSA exam guide covers the full objective list. For hands-on practice with an instructor, the Linux administration training runs in our Kharadi, Pune classroom and live online.

FAQs

What is the difference between chmod 755 and 644?

755 gives the owner read, write and execute and gives group and others read and execute. It suits directories and programs. 644 gives the owner read and write and everyone else read only, which suits ordinary files.

Should I use symbolic or numeric chmod?

Use symbolic mode to change one bit and keep the rest, such as u+x. Use numeric mode in scripts when you want a fixed end state such as 640 regardless of the previous mode.

How do I change only the group of a file?

Run chown :groupname file or chgrp groupname file. Both leave the owner unchanged.

Why can a user delete a file they cannot write to?

Deleting is controlled by write and execute permission on the directory, not the file. Set the sticky bit on shared directories so users can only delete their own files.

What does the capital X do in chmod?

It adds execute only to directories and to files that already have execute permission for some user. It lets you fix permissions recursively without making every file executable.

What does umask 022 mean?

It removes write permission for group and others from newly created files and directories, so files usually end up 644 and directories 755.

When should I use ACLs instead of groups?

Use ACLs when one extra user or group needs access that does not fit the owner, group and others model, such as a read-only auditor. For whole teams, a shared group is simpler to manage.

References

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.