Linux file permissions explained
Linux file permissions control who may read, write or execute each file, set separately for the owner, the group and everyone else.
- Updated Nov 27, 2026
- Markdown
Read an rwx permission string and set modes and owners with chmod and chown.
- A Linux terminal and a test file
Sooner or later a deploy fails with Permission denied: a web server cannot read your files, a script will not run, or a container cannot write to a mounted folder. Almost every time the cause is who owns the file and which three-bit pattern it carries. Learn to read that pattern and these errors become a two minute fix.
How it works#
Every file and folder has one owner (a user), one group and a set of permission bits. The bits are split into three classes: the owner, the group, and everyone else (others). When a process wants to open a file, the kernel picks one class and uses only that class. If you are the owner, the owner bits apply, even if the group bits are more generous. If you are not the owner but are in the group, the group bits apply. Otherwise the others bits apply. Root skips these checks.
Each class has three rights, read (r), write (w) and execute (x). Their meaning is different for files and folders:
| Right | On a file | On a folder |
|---|---|---|
r | Read the contents | List the names inside |
w | Change the contents | Create, rename or delete entries inside |
x | Run it as a program | Enter it and reach files by name |
That last column explains many surprises. To delete a file you need write on the folder that holds it, not on the file. To open /srv/app/data/file.txt you need x on every folder along the path.
Reading the permission string#
See file permissions in the glossary for short definitions. Run this in any folder:
ls -lA line looks like -rwxr-xr-- 1 alice dev 120 Nov 27 notes.sh. The first character is the type (- for a file, d for a directory, l for a symbolic link). The next nine characters are three groups of three: the owner, the group, and others. A - means that right is missing. After the link count come the owner (alice) and the group (dev).
Numbers instead of letters#
Each right has a value: read is 4, write is 2, execute is 1. Add them up for each class.
7= 4 + 2 + 1 (read, write, execute)6= 4 + 2 (read, write)5= 4 + 1 (read, execute)4= read only0= nothing
So 644 means the owner can read and write, everyone else can only read. 755 is the usual setting for scripts and folders. 600 is right for secrets such as private keys.
A worked example: deploy.sh is created with mode -rw-r--r--. You run ./deploy.sh and get Permission denied, because nobody has execute. You run chmod u+x deploy.sh, and ls -l now shows -rwxr--r--. The script runs for you. A teammate in another group can still read it but not run it, which is what you want until you decide otherwise.
Step 1: Change permissions with chmod#
chmod 644 notes.txt
chmod 755 deploy.sh
chmod u+x deploy.shThe last form adds execute for the owner (u) only. Letters are u (owner), g (group), o (others) and a (all). + adds a right, - removes it and = sets it exactly.
What you should see: no output when it works. Run ls -l to see the change.
Warning: do not use chmod 777. It gives every user write access. Also be careful with -R, which changes every file inside a folder, and makes plain files executable if you use a blanket 755.
Step 2: Change the owner with chown#
sudo chown alice:dev notes.txtThis sets the owner to alice and the group to dev. Only root can give a file to another user. Double check the path before you add -R, because a recursive chown on the wrong folder, such as /, can break the system.
What you should see: no output. ls -l notes.txt now shows alice dev.
Step 3: Fix a folder so a service can write to it#
A common case: a service running as user www-data must write to /srv/app/uploads.
sudo chown -R www-data:www-data /srv/app/uploads
sudo chmod 750 /srv/app/uploads750 lets the owner do everything, the group read and enter, and others nothing. Prefer giving the service ownership over opening the folder to everyone.
What you should see: no output. ls -ld /srv/app/uploads shows drwxr-x--- and the owner www-data.
Check it worked#
ls -l notes.txt
stat -c '%a %U:%G %n' notes.txtAfter chmod 644 you should see -rw-r--r-- in the first command. The second prints the number, owner and group in one line, for example 644 alice:dev notes.txt. To test as another user, run sudo -u www-data cat notes.txt: it should print the file or fail with Permission denied, which tells you what that user can really do.
Edge cases and gotchas#
- Folders need x to be entered. A folder at 644 cannot be opened with
cd. Use 755 or 750 for folders. A common cleanup useschmod -R u=rwX,go=rXwhere capitalXsets execute only on folders and already executable files. - Every folder on the path counts. A file can be 644 and still unreadable if a parent folder blocks you. Run
namei -l /full/path/to/fileto see each step. - Docker volumes use numeric IDs. (See Docker volumes and persistent data.) A bind mounted folder belongs to a numeric user ID on the host, and the container user may have a different ID with the same name. If the container gets
Permission denied, compare the IDs withls -lnandidinside the container. - Copying changes ownership.
cpmakes you the owner of the copy, andcp -porrsync -akeeps permissions. Restoring a backup as the wrong user is a classic way to break an app. - Umask sets the default. New files get their mode from the umask, often 022, which gives 644 for files and 755 for folders. A different umask in a service explains files that are unreadable to others.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
Permission denied when running ./deploy.sh | The file lacks the execute bit | Run chmod u+x deploy.sh |
Permission denied on cd folder | The folder has no execute bit for you | Add x with chmod 755 folder if sharing is intended |
chown: changing ownership of 'file': Operation not permitted | Only root can change an owner | Add sudo |
rm: cannot remove 'file': Permission denied | No write on the containing folder | Check ls -ld on the folder |
| Web server shows 403 or cannot read files | The server user cannot read the file or a parent folder | Check ownership and the x bit on parent folders |
Container gets Permission denied on a mounted folder | Host owner and container user IDs differ | Compare ls -ln with id in the container and chown to match |
chmod: cannot access: No such file or directory | Wrong path | Check with ls and pwd |
| SSH ignores your key file | Mode is too open | chmod 600 the key and chmod 700 ~/.ssh |
Real-world scenario#
A web app returns 403 for uploaded images. The files exist, and nginx is running. Mara runs namei -l /srv/app/uploads/photo.jpg and sees that /srv/app is mode drwx------ owned by deploy. nginx runs as www-data, which cannot enter that folder.
She does not reach for 777. She runs sudo chmod 750 /srv/app, then sudo chgrp www-data /srv/app, so the web server user is in the group that may enter. She repeats sudo -u www-data cat /srv/app/uploads/photo.jpg and the file prints.
The fix was one folder and one group, not a blanket change.
Quick reference#
| Mode | Meaning | Common use |
|---|---|---|
| 600 | Owner read and write | Private keys, secrets |
| 644 | Owner read and write, others read | Config and web files |
| 700 | Owner only, with enter on folders | Private folders such as ~/.ssh |
| 750 | Owner all, group read and enter | Shared service folders |
| 755 | Everyone can read and run | Scripts and public folders |
Show a mode as a number: stat -c '%a %n' file.
Security and safety notes#
- Never run
chmod -R 777orchown -Ron/,/etcor/usr. It can break the system and open security holes. - Keep private keys at
600. SSH refuses keys that other users can read, as in log in with SSH keys.
Related lessons#
- Essential Linux commands for servers: the commands used here
- Create a non-root sudo user: users and groups in practice
- Docker volumes and persistent data: owner problems with mounts
- Log in to a server with SSH keys: why key files need 600
Next#
Check what you learned
Frequently asked questions
What does chmod 755 mean?
The owner can read, write and execute (7). The group and everyone else can read and execute (5) but not write.
Why should I never use chmod 777?
It lets every user on the machine change or replace the file. Give the smallest permission that works instead.
What does the x bit mean on a folder?
On a folder, x means you may enter it and reach the files inside by name. Without x on a folder you cannot cd into it, even if you can read its listing.
Why can I not delete a file I own?
Deleting removes a name from the folder, so it needs write permission on the folder, not on the file. Check ls -ld on the folder.
Sources
Keep going: guides and tutorials
- Install a Self-Hosted PaaS on Your Own Server in Five Minutes One installer download, one setup token, one sample app. The full Levelrail install on a fresh Linux server, with the checks and the fixes.
- Manage Secrets Self-Hosted: Env Vars and Master Key Rotation Set env vars and encrypted secrets on a self-hosted server, apply changes safely, and rotate the master key with no downtime without locking yourself out.