chmod Command Guide for Changing File Permissions
chmod changes the permissions on a file or directory — who is allowed to read it, write to it, or execute it.
What is chmod, and Why Use It?
Every file and directory on a Linux system carries a small set of permission bits: nine flags that say whether the owner, the group, and everyone else can read, write, or execute it. chmod (“change mode”) is the command that edits those flags.
There are two ways to write permissions:
- Symbolic —
chmod u+x script.sh(“add execute for the user”) - Octal —
chmod 755 script.sh(three digits: owner, group, others)
Both do exactly the same thing; the octal form is just more compact once you know the numbers.
Why Learn chmod?
- You’ll hit “Permission denied” constantly until you understand this — it’s the most common error a beginner sees.
- Scripts won’t run until you mark them executable (
chmod +x). - Servers and configs need locking down — a world-writable config or a public
777directory is a security hole. - It’s interview and sysadmin-fu basics — knowing what
755and644mean is assumed knowledge on Linux jobs.
Permission bits are the foundation of everything else in this section:
chownandchgrpdecide who you are,chmoddecides what they can do.
1. See the Permissions First
Before changing anything, look at what’s there. ls -l shows the permission string in column one:
ls -l notes.txt
Example:
$ ls -l deploy.sh
-rw-r--r-- 1 alice devs 412 Dec 4 09:12 deploy.sh
Read the string in three chunks of three:
- rw- r-- r--
│ │ │ └── others (everyone else)
│ │ └───────── group
│ └──────────────── owner (alice)
└────────────────────── type: - file, d directory, l symlink
r= read,w= write,x= execute (or “traverse” for a directory),-= no permission.- The first character is the file type, not a permission.
2. Add or Remove Permissions (Symbolic Mode)
The symbolic form uses u (user/owner), g (group), o (others), a (all), plus + to add, - to remove, and = to set exactly:
chmod u+x file
chmod g-w file
chmod o=r file
Example:
# Make a script executable for its owner only
chmod u+x deploy.sh
# Take write access away from everyone except the owner
chmod go-w secrets.txt
# Make a config readable by everyone, writable by nobody else
chmod a=r,go=w config.txt
- This is the safest style for small changes: it says exactly what changes and leaves the rest untouched.
- You can chain several clauses with commas:
chmod u=rw,g+r,o=r file.
3. Set Permissions with Octal Numbers
Each of the three chunks becomes one digit, built from r=4, w=2, x=1:
| Permission | Bits | Digit |
|---|---|---|
--- | 000 | 0 |
r-- | 100 | 4 |
rw- | 110 | 6 |
r-x | 101 | 5 |
rwx | 111 | 7 |
Three digits = owner, group, others:
chmod 755 script.sh
chmod 644 notes.txt
Example:
$ chmod 755 deploy.sh
$ ls -l deploy.sh
-rwxr-xr-x 1 alice devs 412 Dec 4 09:12 deploy.sh
755= owner can do everything (rwx), group and others can read and execute (r-x) — the standard for scripts and executables.644= owner can read and write, everyone else can only read — the standard for regular files.600= only the owner — for private files like keys and secrets.700= only the owner, executable — for private scripts.
4. Change Permissions Recursively
Add -R to apply the change to a directory and everything inside it:
chmod -R 755 /srv/web/
Example:
# Give a whole project directory standard permissions
chmod -R u+rwX,go+rX project/
- ⚠️ Always preview first with
findwhen recursing over system directories — a wrongchmod -Rcan break a package:
# See what a recursive change WOULD touch before running it
find /srv/web/ -type f -name "*.html"
- Note the capital
Xabove: it means “execute only if already executable or a directory”, which avoids marking every file executable.
5. Make a Script Executable
This is the single most common reason beginners learn chmod:
chmod +x script.sh
./script.sh
Example:
$ touch backup.sh
$ ls -l backup.sh
-rw-r--r-- 1 alice devs 0 Dec 4 09:20 backup.sh
$ chmod +x backup.sh
$ ls -l backup.sh
-rwxr-xr-x 1 alice devs 0 Dec 4 09:20 backup.sh
- Without
x, the shell refuses to run the file (“Permission denied”) — the file exists, you just haven’t marked it executable. chmod +xwithout au/g/oprefix applies to all three classes at once.
6. Lock Down a Directory or File
Tightening permissions is the mirror image of opening them:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
Example:
# Only alice can enter her SSH directory or read her private key
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519 ~/.ssh/authorized_keys
sshdrefuses to work if private keys are readable by others —600is the required setting.- Home directories are conventionally
750or700on multi-user systems.
Common Pitfalls
chmod 777is almost never the answer. It gives every user on the system full control of the file. If you’re reaching for777to fix a “Permission denied”, the real fix is almost alwayschownor a narrowerchmod.- Forgetting
-Ron directories. Changing a directory’s permissions does not automatically change the files inside it. - Marking everything executable.
chmod -R +x dir/putsxon data files too; use+X(capital) orfind -type f -execto target only what should run. - Running
chmodon system files as root. A wrong change to/etc/passwdor an init script can make the system unbootable. Check what you’re changing withls -lfirst. - Expecting
chmodto affect a running process. Permission changes apply to new accesses; already-open file handles keep working until reopened.
Related Pages
| Page | Why it’s related |
|---|---|
| chown | Change who owns a file — the other half of access control |
| chgrp | Change a file’s group |
| umask | Controls the default permissions new files get |
| ls | ls -l is how you read the permissions |
| id | Shows which user and groups you are when setting permissions |
chmod Cheatsheet
| Command | Meaning |
|---|---|
chmod u+x file | Add execute for the owner |
chmod g-w file | Remove write for the group |
chmod o=r file | Set others to read-only |
chmod a+x file | Add execute for everyone |
chmod 755 file | Owner full; group/others read + execute |
chmod 644 file | Owner read/write; others read-only |
chmod 600 file | Owner only — private files |
chmod 700 dir | Owner only, traversable — private directories |
chmod -R 755 dir/ | Apply recursively (preview first!) |
chmod +x script.sh | Make a script executable |
ls -l file | Read the current permissions |