chmod explained: Linux file permissions
Updated · Every command on this page ran in our practice shell
Short answer
chmod changes who may read (r = 4), write (w = 2) and execute (x = 1) a file, for the owner, the group and everyone else. chmod 644 file is the usual mode for files, 755 for scripts and folders, and 600 for secrets. chmod +x script.sh makes a script runnable.
Every file and folder on Linux and macOS records who may read it, write it and execute it. ls -l shows those permissions and chmod changes them. The examples below ran in a practice shell on a small bakery's server folder; type into the mini terminal under each one to try it.
Read permissions with ls -l
The first column of ls -l is ten characters. The first is the type: - for a file, d for a directory, l for a symbolic link. The other nine are three groups of three: permissions for the user who owns the file, for its group, and for others. After that come the link count, the owner, the group, the size in bytes, the last-modified date and the name.
learner@shellstreak:~$ ls -l bakery total 24 -rwxr-xr-x 1 learner learner 77 Feb 27 07:30 backup.sh -rw-r--r-- 1 learner learner 145 Feb 27 07:30 deploy.sh -rw-rw-rw- 1 learner learner 48 Feb 27 07:30 notes.txt drwx------ 2 learner learner 4096 Feb 27 07:30 private drwxr-xr-x 3 learner learner 4096 Feb 27 07:30 reports drwxr-xr-x 2 learner learner 4096 Feb 27 07:30 site
What r, w and x mean
On a file, r lets you read it, w lets you change it and x lets you run it as a program. On a folder, r lets you list its contents, w lets you create, rename and delete files inside it, and x lets you enter it and reach the files in it. A - in a slot means that permission is missing. ls -ld shows the folder's own line instead of its contents.
learner@shellstreak:~$ ls -ld bakery/private drwx------ 2 learner learner 4096 Feb 27 07:30 bakery/private
Numeric modes: 644, 755, 600 and 700
Each digit is one triplet (user, group, others), and it's the sum of r = 4, w = 2 and x = 1. So 6 is rw-, 5 is r-x and 7 is rwx. The four you'll use most: 644 for normal files (you edit, everyone reads), 755 for scripts and folders (you edit, everyone can run or enter), 600 for secrets like .env files and SSH keys, and 700 for private folders. A numeric mode replaces all nine bits at once.
learner@shellstreak:~$ chmod 600 bakery/.env && ls -l bakery/.env -rw------- 1 learner learner 60 Feb 27 07:30 bakery/.env
Symbolic modes: u+x, go-w, a+r
The symbolic form changes only what you name and leaves the rest alone. Pick who (u user, g group, o others, a all), an operator (+ add, - remove, = set exactly), and the letters. You can list several changes with commas: chmod u+x,go-w file.
learner@shellstreak:~$ chmod go-w bakery/notes.txt && ls -l bakery/notes.txt -rw-r--r-- 1 learner learner 48 Feb 27 07:30 bakery/notes.txt
Change a folder and everything in it with -R
chmod -R applies the change recursively. Prefer symbolic modes here: chmod -R 755 dir would also make every plain file executable, while chmod -R go-rwx dir only takes access away from the group and others. To open a website folder to a web server, chmod -R a+rX site adds read everywhere and execute (capital X) only on folders, so the server can enter them.
learner@shellstreak:~$ chmod -R go-rwx bakery/reports && ls -lR bakery/reports bakery/reports: total 8 drwx------ 2 learner learner 4096 Feb 27 07:30 2026 -rw------- 1 learner learner 21 Feb 27 07:30 summary.txt bakery/reports/2026: total 4 -rw------- 1 learner learner 25 Feb 27 07:30 march.csv
Fix Permission denied when running a script
Running a script as ./deploy.sh needs the execute bit. Without it, bash refuses with Permission denied and exit code 126. chmod +x deploy.sh adds it (or chmod u+x for just you). The script's first line, the shebang (#!/bin/bash), tells the system which program should run it.
learner@shellstreak:~/bakery$ ./deploy.sh bash: ./deploy.sh: Permission denied
Make a script executable with chmod +x
After chmod +x, the file shows an x in its permissions and ls -F marks it with *. Running it with bash deploy.sh works even without x, because then bash is the program and the script is just a file it reads.
learner@shellstreak:~/bakery$ chmod +x deploy.sh && ./deploy.sh Deployed to /tmp/www: index.html menu.html style.css
Write a script without an editor: here-docs
A here-doc writes several lines into a file at once: every line up to the closing EOF goes in. Quoting it as 'EOF' keeps $1 (the script's first argument) exactly as you typed it:
cat > hello.sh <<'EOF'
#!/bin/bash
echo "Hello, $1"
EOF
bash hello.sh AnaOwners and groups: chown
The two names in ls -l are the owner and the group. Only the system administrator (root) can give a file to another user, with sudo chown sam file or sudo chown sam:bakers file for owner and group together. You can't run those in this practice shell, which has no other users, but you can always read who owns what with ls -l.
Check yourself
One real exercise from the “Permissions & scripts” unit. No account needed.bakery/.env holds the shop's API key, and right now everyone can read it. Using a number, make it readable and writable by you only. Then check with ls -l bakery/.env.
What's checked: the permissions of bakery/.env.
Common mistakes
Reaching for
chmod 777(orchmod -R 777) to make an error go away. It lets every user and program change the files, secrets included. Add only the permission that's missing.Running
chmod -R 755orchmod -R 644on a folder tree. The first makes every file executable; the second removesxfrom the folders, so nobody can enter them.Forgetting that a folder needs
xto be entered. A folder withrbut noxcan be listed by name, but its files can't be opened.Leaving
.envfiles and private keys at644. Use600so only you can read them; SSH refuses keys that others can read.Using
sudoto run a script that only lacksx. Fix the permission withchmod u+x, or run it withbash script.sh.
Questions
What does chmod 755 mean?+
The owner can read, write and execute (`7` = 4 + 2 + 1), and the group and everyone else can read and execute (`5` = 4 + 1). It's the usual mode for scripts, programs and folders.
What's the difference between chmod +x and chmod u+x?+
`u+x` gives execute permission to the owner only. `+x` with no letter in front applies to user, group and others (minus anything your umask masks out), which with the common umask `022` means all three.
How do I see permissions as numbers?+
On Linux, `stat -c '%a %n' file` prints something like `644 file`. On macOS, use `stat -f '%Lp %N' file`.
Reading is step one. Now make it stick.
Practise this in a five-minute lesson with instant feedback. No account needed.