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:

Reading the grid
Take -rw-r--r--:
- Character 1 is the type:
-file,ddirectory,lsymlink. - 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:
| Symbolic | Octal | Meaning |
|---|---|---|
rwx | 7 | read + write + execute |
rw- | 6 | read + write |
r-x | 5 | read + execute |
r-- | 4 | read only |
--- | 0 | nothing |
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.
chmod 644 notes.txt
chmod 755 deploy.sh
chmod 600 ~/.ssh/id_ed25519Worked 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:
stat -c '%a %n' deploy.sh # Linux, prints e.g. 750 deploy.sh
stat -f '%A %N' deploy.sh # macOS / BSD equivalentRather 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 644 filenameOwner can read, write; group can read; others can read.
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.
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.
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:
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:
chmod -R u+rwX,go-w ~/proj
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:
# Owner full access; group/other read; directories stay traversable; plain files don't become executable
chmod -R u=rwX,go=rX ~/projX 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:
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:
chmod +x deploy.sh
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):
./deploy.shdeploy.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:
#!/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:
chmod u+x private.sh # execute for the owner onlyThat 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:
sudo chown deploy:developers report.txt
The forms:
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 groupFor a whole tree, add -R:
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,chownfails withOperation 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:
chgrp developers report.txt # owner can do this if they're in developersSo 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:
sudo chown $USER:$USER ~/.config/app/settings.jsonThis 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.
umask # show the current mask, e.g. 0022
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:
| umask | New file (666 - mask) | New dir (777 - mask) | Who gets the new file |
|---|---|---|---|
022 | 644 | 755 | owner writes, others read (the common default) |
002 | 664 | 775 | owner and group write, others read (shared teams) |
077 | 600 | 700 | owner only (private, good for sensitive work) |
027 | 640 | 750 | owner 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:
umask 077 # everything you create now is owner-only
touch secret.txt # -> 600The 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):
echo 'umask 077' >> ~/.bashrcSystem-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.

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.
sudo chmod u+s /usr/local/bin/mytool # or: chmod 4755setuid 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.
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.
sudo chmod +t /shared/dropbox # or: chmod 1777In a four-digit octal mode, the leading digit is setuid (4) + setgid (2) + sticky (1):
| Mode | Bit | Typical use |
|---|---|---|
4755 | setuid | a trusted root helper like passwd |
2775 | setgid | a shared group directory |
1777 | sticky | a 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):
sudo find / -perm -4000 -type f 2>/dev/null # all setuid files
sudo find / -perm -2000 -type f 2>/dev/null # all setgid filesCompare 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:
setfacl -m u:deploy:rw report.txt
Read the ACL back with getfacl:
getfacl report.txtIt 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:
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:
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
- chmod calculator: convert between rwx and octal.
- Find files by owner, group, or permission: audit modes and setuid binaries with find -perm.
- How to create a group on Linux: the groups you assign with chown and setgid.
- Fix SSH "permissions are too open": the 600 rule in practice.
Sources
Authoritative references this article was fact-checked against.
- chmod(1) Linux manual page (man7.org)man7.org
- chmod(2) Linux manual page (mode bits)man7.org
- umask(1p) POSIX manual page (man7.org)man7.org
- umask(2) Linux manual page (man7.org)man7.org
- chown(1) Linux manual page (man7.org)man7.org
- inode(7) Linux manual page (special mode bits)man7.org
- setfacl(1) Linux manual page (man7.org)man7.org
- exec(3p) POSIX manual page (man7.org)man7.org
- getfacl(1) Linux manual page (man7.org)man7.org





