TechEarl

Linux File Permissions Explained (chmod and Octal)

Read and set rwx permissions, the octal behind 644 and 755, chmod +x, chmod -R with the capital-X trick, chown, umask defaults, setuid, setgid, the sticky bit, and ACLs with getfacl and setfacl.

Ishan KarunaratnePublished ⏱️ 17 min readUpdated
Share thisCopied
Linux file permissions explained: rwx and octal (644, 755), chmod +x, chmod -R with capital X, chown, umask, setuid, setgid, sticky bit, and ACLs.

Every Linux file has three permissions (read, write, execute) for three classes of user (owner, group, other), and chmod sets them, either as octal numbers like 644 and 755 or symbolically like u+x. This guide covers that model, then the tools around it: chmod +x, chown, umask defaults, setuid, setgid, the sticky bit, and ACLs. Start by reading the grid straight off ls -l:

Terminal showing ls -l output: a file at -rw-r--r-- (644), a script at -rwxr-xr-x (755), and a directory at drwxrwxr-x, with owner, group, and other permission columns.
The first column is the permission grid: type, then rwx for owner, group, and other.

Reading the grid

Take -rw-r--r--:

  • Character 1 is the type: - file, d directory, l symlink.
  • Characters 2-4 are the owner's permissions: rw- = read, write, no execute.
  • Characters 5-7 are the group's: r-- = read only.
  • Characters 8-10 are other (everyone else): r-- = read only.

So -rw-r--r-- means the owner can read and write; everyone else can only read. That is the default for a normal file, and the octal for it is 644. A trailing + (-rw-rw-r--+) means the file also carries ACL entries, and an s or t where an x would be is one of the special bits.

The octal shorthand

Each rwx triplet is a number: read = 4, write = 2, execute = 1. Add them up per class:

SymbolicOctalMeaning
rwx7read + write + execute
rw-6read + write
r-x5read + execute
r--4read only
---0nothing

So three digits describe the whole grid:

  • 644 (rw-r--r--), normal file: owner edits, others read.
  • 755 (rwxr-xr-x), script or directory: owner full, others read/run.
  • 600 (rw-------), private file, like an SSH key: owner only.
  • 700 (rwx------), private directory: only the owner can enter.
bash
chmod 644 notes.txt
chmod 755 deploy.sh
chmod 600 ~/.ssh/id_ed25519

Worked the other way, chmod 750 deploy.sh reads as owner 7 (rwx = 4+2+1), group 5 (r-x = 4+1), other 0 (---): the owner can read, write, and run it, the group can read and run it, everyone else gets nothing.

To read a file's mode as the octal number directly, instead of decoding the rwx string by eye:

bash
stat -c '%a %n' deploy.sh        # Linux, prints e.g. 750 deploy.sh
stat -f '%A %N' deploy.sh        # macOS / BSD equivalent

Rather than do the arithmetic in your head, tick what each class should be allowed to do and read off the octal (or type an octal to decode it):

chmod permissions calculator
Read4Write2Execute1ownergroupother
Special
Symbolicrw-r--r--
chmod 644 filename

Owner can read, write; group can read; others can read.

AI CLI prompt

Paste this into your terminal AI and it runs the command for you, installing the tool first if you do not have it. Works with Claude Code, OpenAI Codex CLI, Gemini CLI, GitHub Copilot CLI, Aider, Cursor Agent, Warp, OpenCode, Cline and any other CLI coding agent.

prompt
Goal: apply these Unix file permissions to the target path.

Run this command in my shell:

    chmod 644 filename

Before you run it, tell me in one line exactly what it changes. Never run it as root or recursively against a system path. Run only this command, nothing else, and confirm the result when it is done.

You run this at your own risk. An AI agent can execute commands on your machine; review what it does before approving. TechEarl is not liable for the outcome, see the Terms of Service.

Quick presets
ModeSymbolicUsed for

Tap any mode to load it, set the path and scope, then copy the command. Your selection is saved on this device.

A standalone version with the common modes laid out lives on the chmod calculator page.

Symbolic chmod, when you want to change one bit

Numeric sets all nine bits at once. Symbolic changes just what you name, which is safer when you do not want to disturb the rest:

bash
chmod u+x deploy.sh        # add execute for the owner (u)
chmod go-w shared.txt      # remove write for group and other
chmod a+r public.txt       # add read for all (a = ugo)

u owner, g group, o other, a all; + add, - remove, = set exactly.

Execute means different things for files and directories

This is the part that confuses everyone. On a file, the execute bit (x) means "can be run as a program". On a directory, x means "can enter / traverse it" (cd into it, access files inside by name). A directory you can read but not execute lets you list names but not actually reach the files. That is why directories are 755 (with x) and not 644. The capital-X form on chmod -R exists exactly for this; see chmod recursively.

chmod recursively

chmod -R applies a mode to a directory and everything inside it. The safe default form uses the capital X:

bash
chmod -R u+rwX,go-w ~/proj
Terminal showing chmod -R u+rwX,go-w on a project directory, then ls -lR confirming the directory keeps execute while regular files do not gain it.
-R walks the whole tree; the capital X adds execute only to directories and already-executable files, not to plain files.

Why chmod -R 644 breaks your directories

The naive recursive commands are chmod -R 755 dir and chmod -R 644 dir. The second is a disaster: it strips the execute bit from directories, and as the section above explains, a directory without execute cannot be entered. Suddenly you cannot cd into your own folders or reach the files inside, even though you can still see the names. Numeric modes apply the same nine bits to files and directories alike, but directories need execute and regular files usually should not have it.

The capital X fix

Capital X means "execute, but only for directories and files that are already executable". It is exactly what a recursive change wants:

bash
# Owner full access; group/other read; directories stay traversable; plain files don't become executable
chmod -R u=rwX,go=rX ~/proj

X keeps directories enterable and existing scripts runnable, but it does not turn every text file into a program, which lowercase x would. This is the single most useful chmod fact most people never learn, and it is also the repair for a tree you already broke with -R 644.

Set files and directories separately with find

For precise control, split the two with find:

bash
find ~/proj -type d -exec chmod 755 {} +     # directories: 755
find ~/proj -type f -exec chmod 644 {} +     # files: 644

-type d matches directories and -type f regular files, so each gets the mode that fits it. This suits a web root or a release artifact where no file should be executable, but note that it strips execute from every regular file, scripts included. If the tree holds scripts that must stay runnable, use the capital X form above instead, or limit the file pass to non-executables with find ~/proj -type f ! -perm -u+x -exec chmod 644 {} +. For the find side in depth, see find files by owner, group, or permission.

Make a file executable

You wrote a script, ran it, and got Permission denied. The file needs the execute bit:

bash
chmod +x deploy.sh
Terminal showing ls -l of a script at -rw-r--r-- (not executable), then chmod +x, then ls -l showing -rwxr-xr-x with the execute bits set.
Before: rw-r--r-- (no x). After chmod +x: rwxr-xr-x. The script can now be run directly.

No sudo here: it is your file, so you can change its mode yourself.

Run it with ./

Once executable, run it by path. The ./ is required for a script in the current directory, because . is not on your PATH (for good security reasons):

bash
./deploy.sh

deploy.sh alone gives command not found; ./deploy.sh runs it. That is a path issue, not a permission one. To run it by name from anywhere, move it onto your PATH (for example ~/.local/bin or /usr/local/bin).

The shebang decides how it runs

The execute bit only says "this may be run". The first line, the shebang, says with what:

bash
#!/bin/bash
echo "hello from bash"

Common shebangs: #!/bin/bash, #!/usr/bin/env python3, #!/bin/sh. Without a shebang, the kernel refuses to run the file directly (execve fails with ENOEXEC), and what happens next depends on who launched it: bash and most shells fall back to running it as a shell script, while other launchers just fail. Either way it may not run under the interpreter you wrote it for, so always add one. #!/usr/bin/env python3 is the portable form because it finds python3 on the PATH rather than assuming a fixed location.

chmod +x adds execute for everyone

Plain chmod +x sets the execute bit for owner, group, and other (it respects your umask, but in practice gives rwxr-xr-x). To make a script executable only by you:

bash
chmod u+x private.sh        # execute for the owner only

That is the tighter choice for anything sensitive. Match the permission to who should actually be allowed to run it.

Change file owner and group with chown

Permissions decide what the owner and group may do; chown decides who the owner and group are. Set both at once with user:group, which is a root task:

bash
sudo chown deploy:developers report.txt
Root terminal showing ls -l of a file owned by techearl, then chown deploy:developers on it, then ls -l confirming the owner and group changed.
chown user:group sets both the owner and the group in one go. ls -l confirms the change.

The forms:

bash
sudo chown deploy file              # owner only
sudo chown deploy:developers file   # owner AND group
sudo chown :developers file         # group only (leading colon)
sudo chown deploy: file             # owner, and set group to deploy's primary group

For a whole tree, add -R:

bash
sudo chown -R deploy:developers /srv/app

-R walks the directory. This is the standard fix after deploying files as the wrong user, or after a git clone/tar as root left everything owned by root. It pairs with recursive chmod when both owner and mode are wrong.

chown vs chgrp, and who is allowed

  • Changing the owner always needs root. A normal user cannot give a file away to someone else (that would let people dodge quotas and plant files). Without sudo, chown fails with Operation not permitted.
  • Changing only the group can be done by the file's owner with chgrp, but only to a group they themselves belong to:
bash
chgrp developers report.txt         # owner can do this if they're in developers

So chgrp (or chown :group) is sometimes available without sudo; reassigning the owner never is.

The classic case: a root-owned file you cannot edit

You ran something with sudo and now a file in your home is owned by root and you cannot write it. Hand it back:

bash
sudo chown $USER:$USER ~/.config/app/settings.json

This is the same root cause behind sudo ssh-keygen making an unusable key: elevation created root-owned files in your space.

Linux umask: default permissions

chmod sets the permissions on a file that already exists. umask decides the permissions a new file is born with. It is a mask of bits to remove from the system defaults.

bash
umask          # show the current mask, e.g. 0022
Terminal showing umask output 0022, a new file created at 644, then umask 077 and a new file created at 600, demonstrating how the mask removes permission bits.
With umask 022 a new file is 644; with umask 077 it is 600. The mask is subtracted from the base mode.

The base mode is 666 for files and 777 for directories (the system never grants execute on a new file automatically). The umask is removed from that:

umaskNew file (666 - mask)New dir (777 - mask)Who gets the new file
022644755owner writes, others read (the common default)
002664775owner and group write, others read (shared teams)
077600700owner only (private, good for sensitive work)
027640750owner writes, group reads, others nothing

So a umask of 022 is why your new files come out 644 and not 666, and your new directories 755. It is not arithmetic subtraction exactly (it is a bitwise clear), but for the usual values it reads like subtraction.

Change it for the current session:

bash
umask 077        # everything you create now is owner-only
touch secret.txt # -> 600

The change lasts until the shell exits. It affects only files created after you set it, not existing ones; to change those, use chmod.

To make it stick for your account, add it to your shell startup (~/.bashrc, ~/.zshrc, or ~/.profile):

bash
echo 'umask 077' >> ~/.bashrc

System-wide defaults live in /etc/login.defs (UMASK) and /etc/profile, which need root to edit. A tighter umask is a cheap, broad hardening win, especially on shared machines: set 077 and new files are private by default instead of world-readable.

setuid, setgid, and the sticky bit

Beyond the nine rwx bits there is a fourth octal digit holding three special bits: setuid, setgid, and the sticky bit. They show in ls -l as an s or t where an x would be. umask does not touch them.

Terminal showing ls -l of /usr/bin/passwd with rws (setuid) and ls -ld of /tmp with a trailing t (sticky bit).
passwd shows rws: the setuid bit. /tmp ends in t: the sticky bit.

setuid (4): run as the file's owner

A setuid executable runs with the owner's identity, not the caller's. The canonical example is /usr/bin/passwd: it is owned by root and setuid, so an ordinary user running it can update /etc/shadow (which only root can write) for the duration of that command. You will see -rwsr-xr-x; the s replaces the owner's x.

bash
sudo chmod u+s /usr/local/bin/mytool     # or: chmod 4755

setuid on a program you do not fully trust is dangerous: any flaw in it becomes a root exploit. Set it sparingly, and never on a shell or interpreter.

setgid (2): run as the file's group, or inherit it on a directory

setgid does two different things:

  • On an executable, it runs with the file's group.
  • On a directory, new files created inside inherit the directory's group instead of the creator's primary group. This is the key to a shared project folder: everyone's new files stay group-owned by the team.
bash
sudo chmod g+s /srv/project       # or: chmod 2775   (directory: inherit group)

You will see drwxrwsr-x on such a directory; the s is in the group's slot.

Sticky bit (1): only the owner can delete, in a shared directory

On a world-writable directory, the sticky bit means a file can only be deleted or renamed by its owner (or root), even though anyone can create files there. That is why /tmp is drwxrwxrwt: everyone can write, but you cannot delete someone else's temp files.

bash
sudo chmod +t /shared/dropbox     # or: chmod 1777

In a four-digit octal mode, the leading digit is setuid (4) + setgid (2) + sticky (1):

ModeBitTypical use
4755setuida trusted root helper like passwd
2775setgida shared group directory
1777stickya world-writable scratch dir like /tmp

Audit setuid binaries

Attackers hunt for setuid binaries because each is a potential privilege-escalation path. List them (root, so find can read every directory):

bash
sudo find / -perm -4000 -type f 2>/dev/null      # all setuid files
sudo find / -perm -2000 -type f 2>/dev/null      # all setgid files

Compare against a known-good baseline; an unexpected setuid binary (especially one not from a package) is a red flag. The find -perm syntax is covered in find files by owner, group, or permission.

ACLs with getfacl and setfacl

The classic rwx model only has three slots: owner, one group, and everyone else. When you need to grant one extra person access to a file without making it world-readable or restructuring groups, that is what POSIX ACLs are for. Grant access with setfacl on a file you own:

bash
setfacl -m u:deploy:rw report.txt
Terminal showing setfacl -m u:deploy:rw on a file, then getfacl listing the owner permissions plus the extra user:deploy:rw entry and a mask line.
setfacl -m adds a named-user entry; getfacl shows the base permissions plus the extra ACL entries and the mask.

Read the ACL back with getfacl:

bash
getfacl report.txt

It prints the owner and group permissions plus any extra entries (user:deploy:rw-) and a mask line. The mask caps the maximum effective permission for named users and groups; if a named entry seems ignored, the mask is usually why.

The common operations:

bash
setfacl -m u:deploy:rw file        # give user deploy read/write
setfacl -m g:auditors:r file       # give group auditors read
setfacl -x u:deploy file           # remove deploy's entry
setfacl -b file                    # strip ALL ACLs, back to plain rwx

-m modifies/adds, -x removes one entry, -b removes everything. A file with extra ACLs shows a + at the end of its ls -l line, which is the signal to run getfacl to see the full picture.

Default ACLs: new files inherit them

On a directory, a default ACL is applied to everything created inside it afterward, which is how you make a whole shared tree grant a user or group access automatically:

Only the file's owner (or root) can change its ACL. A shared directory like /srv/project is usually created with sudo and left owned by root, so run these as root; drop the sudo only on a directory you own:

bash
sudo setfacl -d -m g:developers:rwx /srv/project    # default for new entries
sudo setfacl -R  -m g:developers:rwx /srv/project    # apply to existing entries too

-d sets the default (inherited) ACL; -R applies recursively to what is already there. I usually run both: -R for the current contents, -d for future ones.

When to reach for ACLs vs groups

Prefer a group when several users share access long-term; it is simpler and shows up everywhere. Reach for an ACL when you need a one-off exception ("just give Sam read on this one log") without creating a group or widening the file's group permissions. ACLs require the filesystem to be mounted with ACL support, which is the default on ext4 and xfs.

FAQ

644 sets the file to rw-r--r--: the owner can read and write (6 = 4+2), while group and other can only read (4). It is the standard mode for a normal, non-executable file. Scripts and directories use 755 instead, which adds the execute bit.

755 (rwxr-xr-x) adds the execute bit, so the owner can run/enter it and others can read and run/enter it. 644 (rw-r--r--) has no execute. Use 755 for scripts and directories, 644 for regular files. A directory needs the execute bit to be enterable at all.

Numeric (chmod 644) sets all nine bits at once and is best when you want a known end state. Symbolic (chmod u+x) changes only the bits you name and leaves the rest alone, which is safer for a targeted tweak like adding execute without touching read/write.

644 has no execute bit, and a directory needs execute to be entered. Applied recursively, it stripped execute from every directory, so you can no longer cd into them or reach files by path. Fix it with chmod -R u=rwX,go=rX dir, where the capital X restores execute on directories without making plain files executable.

Lowercase x sets the execute bit on everything it touches, including plain files. Capital X sets execute only on directories and on files that are already executable. For recursive operations you almost always want capital X.

Use find to separate them: find dir -type d -exec chmod 755 {} + for directories and find dir -type f -exec chmod 644 {} + for files. The file pass also strips execute from scripts; if any need to stay runnable, use chmod -R u=rwX,go=rX dir instead.

That is a path issue, not a permission one. A script in the current directory is not on your PATH, so you must run it as ./script.sh, not script.sh. To run it by name from anywhere, move it into a directory on your PATH such as /usr/local/bin.

Check the shebang, the first line. #!/bin/bash runs it under bash; #!/usr/bin/env python3 under python3. With no shebang, the kernel cannot run it directly; a shell launching it usually falls back to running it as a shell script, which may not match what you wrote, and other launchers fail outright. Add the right shebang line.

chown changes the owner (and optionally the group); chgrp changes only the group. Changing the owner always requires root. Changing only the group can be done by the file's owner with chgrp, as long as they are a member of the target group.

Set umask 077. New files then come out 600 (owner read/write only) and directories 700. Add umask 077 to your ~/.bashrc or ~/.zshrc to make it permanent for your account.

That is the sticky bit. On a world-writable directory it restricts deletion: anyone can create files, but only a file's owner (or root) can delete or rename it. It stops users from removing each other's files in shared directories like /tmp.

Set the setgid bit on the directory: chmod g+s dir (or chmod 2775). Files created inside then inherit the directory's group rather than each user's primary group. For a specific extra user or group, a default ACL (setfacl -d -m g:developers:rwx dir) does the same job for access rights.

Use a group for ongoing shared access among several users; it is simpler and visible in standard tooling. Use an ACL for a one-off grant to a single extra user or group without restructuring groups or making the file's group permissions wider than you want.

See also

Sources

Authoritative references this article was fact-checked against.

TagsLinuxchmodchownumaskFile PermissionsOctalsetuidACLchmod recursiveSystem Administration

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Systems and Network Architect · Chief Technology Officer

Systems and network architect and Chief Technology Officer with more than two decades designing, building, and running production software, cloud and network architecture, Linux systems, and the bare metal underneath them, and lately working AI into the stack. A US Army veteran who served in Operation Iraqi Freedom. What I write here is drawn from the full arc of that work, across architecture, engineering, and operations, not any single job.

Keep reading

Related posts

Fix SSH permissions are too open with chmod 600, check ownership and Windows ACLs, then fix Permission denied (publickey) and host key verification failed.

Fix SSH "Permissions Are Too Open" (UNPROTECTED PRIVATE KEY FILE)

SSH refuses your key with WARNING: UNPROTECTED PRIVATE KEY FILE. The one-line fix is chmod 600, plus the full set of ~/.ssh permissions and ownership SSH actually checks, the ordered checklist for Permission denied (publickey), and the known_hosts fix for Host key verification failed. Linux, macOS, Windows.