On Linux, you change file permissions with the chmod command, using either symbolic mode (chmod u+x script.sh) or numeric mode (chmod 755 script.sh); the method you pick depends on whether you're adjusting one bit or setting all nine at once. The command works the same on Ubuntu, Debian, Fedora, RHEL, and Arch because it comes from coreutils, but the permission model underneath β three permission types, three permission classes, and a trailing special-bit column β is where most mistakes happen. This guide gives you the exact syntax, a numeric-to-symbolic conversion table, the recursive and special-bit edge cases, and the failure modes that lock people out of their own files.
What the Ten-Character Permission String Actually Tells You
Run ls -l report.txt and you get something like -rw-r--r--. That first character is the file type, and the remaining nine split into three groups of three: owner, group, and others. Each group maps to read, write, and execute in that order, so rw- means read and write but no execute, while r-- means read only.
Each permission bit has a numeric weight. Read equals 4, write equals 2, and execute equals 1. Add them within a class and you get the familiar octal digit: 7 is full control, 6 is read and write, 5 is read and execute, 4 is read only. Three digits stacked together give the mode you pass to chmod, which is why 644 (owner read-write, everyone else read-only) is the standard for documents.
The ninth character slot carries a surprise. If you see t or s in place of x, or an uppercase S or T where execute should be, a special bit is set. Calling chmod 777 on something you own will clear those bits unless you prefix a fourth digit, so a directory that was drwxrwxrwt (the classic /tmp mode, 1777) silently loses its sticky bit if you run plain chmod 777 on it.
Directories bend the rules in ways files don't. Read on a directory lets you list its contents; write lets you create, rename, or delete entries inside it; execute lets you traverse into it. A directory with mode 666 but no execute bit is nearly useless β you can see names with ls but you cannot cd into it or open any file it contains, which is a common cause of "permission denied" errors that look inexplicable.
Choosing Between Symbolic and Numeric chmod Modes
Symbolic mode is a three-part instruction: who, operator, and permission. chmod g+w file adds write for the group; chmod o-rwx file strips everything from others; chmod u=rw,go=r file sets exact values. Operators are + to add, - to remove, and = to assign absolutely β the = operator clears any bits not listed, which trips people up when they expect additive behavior.
Numeric mode replaces all nine bits at once. That's its strength and its risk. chmod 750 deploy.sh is unambiguous and reproducible in a script; chmod u=rwx,g=rx,o= file means the same thing but is easier to misread. GNU coreutils documentation (the reference implementation shipped on virtually every distribution) treats octal as the canonical form for exact modes and symbolic as the tool for delta edits.
| Task | Symbolic | Numeric | Result |
|---|---|---|---|
| Make script executable by owner | chmod u+x run.sh | chmod 744 run.sh | rwxr--r-- |
| Share a file with your group | chmod g+r notes.md | chmod 640 notes.md | rw-r----- |
| Private directory | chmod 700 ~/.ssh | chmod u=rwx,go= ~/.ssh | rwx------ |
| Standard web file | chmod 644 index.html | chmod u=rw,go=r index.html | rw-r--r-- |
| Web directory | chmod 755 assets/ | chmod u=rwx,go=rx assets/ | rwxr-xr-x |
Use symbolic when you're changing one class and want the other eight bits untouched β especially on system files that already carry a setgid bit. Use numeric when you're setting a known target mode in a deployment script or a Dockerfile. Mixing the two in one command is legal: chmod u+x,g-w file applies both edits.
Setting Permissions on Files and Directories Step by Step
The safe habit is to look before and after. Every change below is reversible, but you want the before-and-after captured so you can spot an accidental wipe of the execute bit on a directory.
1: Check the current mode and ownership: ls -l target shows mode, owner, and group in one line. 2: Decide the target mode. Files usually want 644 or 600; directories want 755 or 700; executables want 755. 3: Apply the change to a single item: chmod 640 budget.csv or chmod g+rw budget.csv. 4: Verify with ls -l target β confirm all nine bits, not just the one you meant to touch. 5: If ownership is the real problem, note that chmod will not fix it. Use chown user:group target, which requires root for files you don't own. 6: For a batch, list the files explicitly or use find (covered below) rather than a broad wildcard.
If step 3 returns "Operation not permitted," you don't own the file and aren't root. If it returns "No such file or directory," check your working directory with pwd before assuming a typo. A mode that looks right but still denies access usually means an ACL or SELinux context is overriding the traditional bits β check with getfacl target and ls -Z target before editing the mode further.
Recursive Changes With chmod -R and Why Directories Need a Separate Pass
chmod -R 755 project/ applies 755 to every file and every directory beneath project/. That's fine for a directory tree of scripts, and wrong for a tree containing regular data files, because 755 makes every file executable. Executable bits on text files aren't a security disaster, but they confuse tooling and make find -executable results noisy.
The Unix convention splits modes by type: directories get 755, files get 644. GNU chmod supports the capital X permission for exactly this. Running chmod -R u=rwX,go=rX project/ gives directories and already-executable files the execute bit while leaving plain files without it. That single command replaces the two-pass pattern of find project -type d -exec chmod 755 {} + followed by find project -type f -exec chmod 644 {} +.
Recursion follows symbolic links only if you pass -H or -L. By default chmod -R does not traverse symlinks, which is protective: a symlink pointing at /etc won't drag your changes into the system directory. Leave that default alone unless you have a specific reason.
Cap the damage by testing on a copy first when the tree is large. A recursive chmod on a home directory can strip execute from every subdirectory in one command, and the recovery involves knowing which directories need the bit restored β often faster from a backup than from reasoning about the tree.
Reading and Setting Special Bits: setuid, setgid, and the Sticky Bit
The fourth octal digit controls the special bits, and it's the part chmod 755 quietly erases. setuid (4) makes an executable run with the file owner's privileges; setgid (2) on a directory makes new files inherit the directory's group; the sticky bit (1) on a directory prevents users from deleting files they don't own.
/usr/bin/passwd is the canonical setuid example at mode 4755 β a binary that must write to /etc/shadow runs with root's effective identity for that operation. drwxrwsr-x (2775) on a shared team directory keeps group ownership consistent no matter who creates a file. /tmp at 1777 is sticky: everyone can write, only owners can delete.
Set them with the four-digit form: chmod 2750 shared/, chmod 4755 tool, chmod 1777 /srv/upload. Symbolic equivalents exist too β chmod g+s shared/, chmod u+s tool, chmod +t /srv/upload β and they're safer when you only want to flip one bit without disturbing the other three digits. Most distributions mount filesystems with nosuid on user-writable paths, so a setuid bit placed on a script in /home usually has no effect; the kernel ignores it. Check the mount options in /etc/fstab if a setuid bit seems inert.
When chmod Fails: Ownership, ACLs, SELinux, and Immutable Bits
"Permission denied" after a successful chmod has four common causes, and the fix differs for each. Identify which one you're hitting before you run another chmod.
Ownership mismatch: you can only chmod files you own (or all files as root). ls -l shows the owner in column three. Fix with chown, not chmod.
POSIX ACLs: an access ACL entry can grant or deny a specific user regardless of the mode bits. getfacl file reveals them; setfacl -m u:alice:r file adds one, and setfacl -b file removes all of them. The ls -l output shows a + after the mode when an ACL is present.
SELinux or AppArmor: mandatory access control sits above the traditional model. On RHEL-family systems, ls -Z file shows the SELinux context, and restorecon -v file resets it to the policy default. A file with the wrong context is denied even at mode 777.
Immutable attribute: chattr +i file makes a file unchangeable even by root. lsattr file shows the i flag; chattr -i file clears it. This one produces "Operation not permitted" from chmod with no obvious explanation, and it's a favorite of hardening scripts and some backup tools.
Diagnose in that order β ownership, ACL, MAC, attribute β because each check is cheap and they fail in a predictable hierarchy.
Applying the Numeric-to-Symbolic Conversion Across Common Modes
Memorize a small table and you'll stop guessing at modes in scripts and Dockerfiles. The pattern: 7 is rwx, 6 is rw-, 5 is r-x, 4 is r--, 0 is ---. Two-digit combinations like 3 (write plus execute, no read) are legal but rare and usually a mistake.
| Octal | Symbolic | Typical use | Risk if too broad |
|---|---|---|---|
| 600 | rw------- | SSH private keys, secrets | Nothing else can read β safe default |
| 640 | rw-r----- | Config files shared with a service group | Group members can read secrets |
| 644 | rw-r--r-- | Web content, documents | World-readable β check for credentials |
| 660 | rw-rw---- | Shared working files | Group can write; watch for collision |
| 700 | rwx------ | Private directories, ~/.ssh | Owner-only β recommended for keys |
| 750 | rwxr-x--- | Deploy directories | Group can traverse and execute |
| 755 | rwxr-xr-x | Public directories, binaries | World can execute; fine for scripts |
| 775 | rwxrwxr-x | Team-writable directories | Group can modify contents |
| 777 | rwxrwxrwx | Almost never correct | Any user can modify or delete |
The 777 entry deserves its own warning. World-writable directories without the sticky bit let any local user delete any file inside, and world-writable executables are a privilege-escalation vector. Some tutorials reach for 777 to "fix" permission errors; that trades a real problem for a worse one. Set the narrowest mode that works, verify, then widen only with a reason.
Octal digits are positional and independent: chmod 741 file gives the owner rwx, the group r--, and others --x. Nothing about one class constrains another, so a file can be owner-read-only (400) while a different file on the same system is owner-full-control (700). There is no hierarchy implied by the digits themselves.
Automating Permission Changes With find and chmod Together
find is the reliable way to change modes across a filtered set of files, because it can select by type, name, age, and current mode before invoking chmod. The -exec ... + form batches arguments and runs far faster than -exec ... ; on large trees.
To fix permissions on web content β directories 755, files 644 β run find /var/www -type d -exec chmod 755 {} + and find /var/www -type f -exec chmod 644 {} +. To find files with the wrong mode first, use find /var/www -type f ! -perm 644 and inspect the list before changing anything.
Sparse files in a working tree can be normalized with a single GNU chmod call using the X permission: chmod -R u=rwX,go=rX /var/www. That covers both passes and preserves the execute bit on any file that already had it, which is useful when a tree mixes scripts and data.
Avoid chmod -R 777 . in a project directory. It's a common copy-paste fix that renders .git objects world-writable, and restoring the correct modes afterward usually means a fresh clone. If you've inherited a tree with broken modes, check the repository's tracked modes with git ls-files -s β Git records only the execute bit, so a 644-vs-664 distinction isn't recoverable from history alone.
File Permissions Compared Across Docker, WSL, and Traditional Ext4
The permission model is not identical everywhere, and the differences bite when you move between environments. On ext4, XFS, and btrfs, the three-class octal model applies as described. On FAT32 and exFAT β common on USB drives and dual-boot shares β there are no Unix permissions at all, so every file mounts with a fixed mode determined by the fmask and dmask mount options.
| Environment | Permission model | Common gotcha | Practical fix |
|---|---|---|---|
| ext4 / XFS / btrfs | Full POSIX modes plus ACLs | None beyond the usual | Standard chmod |
| FAT32 / exFAT USB | No native Unix modes | chmod silently does nothing | Mount with fmask=0133,dmask=0022 in fstab |
| Docker bind mount | Host modes apply to container | Container user UID may not match host | Align UIDs or use --user |
| Docker named volume | Modes stored in the volume | Files created by root in container | chown inside the container or set user: in compose |
| WSL2 on /mnt/c | Windows metadata emulation | chmod may be ignored or slow | Set metadata option in /etc/wsl.conf |
| NTFS via ntfs-3g | Mapped to a single UID/GID | All files appear owned by one user | Mount options control the mapping |
Docker's bind-mount behavior is the most frequent surprise. A file you chmod 600 on the host stays 600 inside the container, but the container process may run as a UID that doesn't own it, so you get "permission denied" on a file you just created. The fix is usually a user: directive in docker-compose.yml or a chown inside the image build, not another chmod.
WSL2's /mnt/c is the second surprise. By default the Windows filesystem is mounted without Linux metadata, so all files report a fixed mode and chmod has no lasting effect. Adding options = "metadata" under [automount] in /etc/wsl.conf and restarting WSL enables real modes on that drive.
Restoring Access After You Lock Yourself Out of a Directory
Stripping the execute bit from a directory β chmod -x ~, for instance β removes your ability to cd into it or access any file within, and the recovery needs one careful step. You can still chmod the directory itself if you know its path, because chmod operates on the inode, not on traversal through the directory's contents.
From a shell where your current directory is the parent, run chmod u+x yourdir to restore owner traversal. If you're already inside the broken directory and cd won't work, chmod on a relative path fails because resolving . requires the very bit you removed. Use an absolute path, or chmod 700 ~ from a sibling shell.
For a subtler lockout β you removed execute from a parent of your shell's working directory β the shell may still function for already-open file descriptors but new commands that touch the path fail. chmod u+x /full/path/parent fixes it. If you've lost ownership entirely, sudo chown -R $USER:$USER /path is the recovery, run from a sudo-capable account.
On a system where you've removed the execute bit from /usr/bin/chmod itself, invoke it via the dynamic loader: /lib/ld-linux-x86-64.so.2 /usr/bin/chmod 755 /usr/bin/chmod restores it without needing the binary to be executable. That trick is the difference between a five-minute fix and a live-CD rescue on a box with no other copy of coreutils available.
FAQ
Does chmod change the owner of a file?
No. chmod only touches the mode bits; ownership changes require chown. On most systems only root can give a file to another user, though a regular user can hand a file to a group of which they are a member. If a file is unreadable and ls -l shows a different owner in column three, chmod will return "Operation not permitted" β the fix is chown or sudo.
Why does chmod 777 sometimes not make a file writable?
Because something above the traditional permission bits is denying access. An SELinux context mismatch, an AppArmor profile, a POSIX ACL deny entry, or an immutable attribute all override mode 777. Check in order: getfacl file, ls -Z file, then lsattr file. On RHEL-family systems with SELinux enforcing, restorecon -v file resets a broken context to the policy default.
What does the trailing dot or plus in ls -l output mean?
A + after the mode means an ACL is attached; a . means an SELinux security context is present (default SELinux labeling under enforcing or permissive mode). Neither changes the nine mode characters, but both can affect effective access. getfacl shows the ACL; ls -Z shows the SELinux context.
Can I use chmod on a symbolic link?
chmod follows a symlink and changes the target's permissions on Linux; the link itself has no meaningful mode. To avoid touching a target you didn't intend, chmod the resolved path explicitly. chmod -R does not traverse symlinks by default, which protects against dragging changes into a linked system directory.
Is 755 or 775 more secure for a shared project directory?
755 means only the owner can write; 775 lets the group write too. For a shared team directory, 2775 β setgid plus 775 β is the standard choice because new files inherit the directory's group instead of the creating user's primary group, which keeps group access consistent. Choose 755 when group members only need to read and execute.
How is a file mode represented in a Dockerfile or compose file?
In Docker, modes live on the host filesystem for bind mounts and inside the volume for named volumes. The --chmod flag on COPY in a Dockerfile sets the mode at build time, e.g. COPY --chmod=644 app.conf. For runtime, set user: in compose or --user on docker run so the container process's UID matches the file owner.
Does chmod work on a FAT32 USB drive?
No. FAT32 and exFAT have no native Unix permission bits, so chmod appears to succeed but has no lasting effect β the kernel reports whatever mode the mount options dictate. To control access, mount with fmask and dmask in /etc/fstab, which set the permission bits reported for files and directories respectively.
How do I change permissions on thousands of files without breaking directories?
Use the capital X permission: chmod -R u=rwX,go=rX /path. It applies execute only to directories and to files that already had it, so directories become traversable and data files stay non-executable. This is a single GNU coreutils call and replaces the two-pass find-plus-chmod workflow on large trees.