Linux Users and Permissions: chmod and chown Without Blind Number Memorizing

Linux permissions are not numbers to memorize, they are a model of owner, group, and other with three rights each. We cover when to use 644, 755, and 600, the real danger of 777, and the storage mistakes that break web apps.
The Direct Answer: Understand the Model, Don't Memorize Numbers
Every file and folder in Linux is governed by three classes only: the owner (user), the group, and other, and each class has three rights: read (r=4), write (w=2), and execute (x=1). A number like 644 or 755 is not a magic code, it is the sum of these rights per class. The first digit is the owner, the second is the group, the third is other. So 644 means the owner reads and writes (4+2=6), the group reads only (4), and other reads only (4). Once you internalize that 6 = read+write, 7 = read+write+execute, and 5 = read+execute, you never need a lookup table again.
The practical rule that covers 95 percent of cases: regular files get 644 (text, images, pages), folders and executable scripts get 755, and secret files like SSH keys and sensitive configs get 600. As for 777, it is a genuine security hole that gives any user on the server write and execute access, and there is almost no legitimate reason to use it on a production server. In this article we build the understanding from the ground up, then walk through the storage folder permission mistakes that break half of Laravel and web apps, and finish with the rule of using sudo instead of logging in as root daily.
The Owner, Group, and Other Model
Run ls -l inside any folder and you will see lines starting with something like -rw-r--r--. The first character tells you the type: a dash for a regular file, d for a directory, l for a symbolic link. After it come nine slots split into groups of three: the first three for the owner, then three for the group, then three for other.
| Symbol | Number | Meaning |
|---|---|---|
| r (read) | 4 | Read a file's content, or list a folder's contents |
| w (write) | 2 | Modify the file, or create and delete inside the folder |
| x (execute) | 1 | Run the file as a program, or enter the folder with cd |
Note one point many people get wrong: execute on a folder does not mean running it, it means the ability to enter and traverse it. That is why folders always need x even if they are read only, and why the natural folder permission is 755, not 644. If you drop a folder to 644, nobody can enter it even if they hold read rights.
How to Read 750 Quickly
Break it into three digits: 7 for the owner (4+2+1, read, write, and execute), 5 for the group (4+0+1, read and execute without write), 0 for other (nothing). This is an excellent permission for a folder that belongs to one team and that you want completely hidden from the rest of the server's users.
644, 755, and 600: When and Why
These three cover nearly all of your daily work:
- 644 for regular files: the owner edits, everyone reads. Suitable for HTML, CSS, images, and text files served by the web server.
- 755 for folders and scripts: the owner owns everything, the rest read and enter. This is the default for project folders and any shell script you want to run.
- 600 for secrets: only the owner reads and writes, nobody else sees anything. Mandatory for a private SSH key, an env file, and any file with passwords. If you raise a private SSH key above 600, the ssh command itself refuses to use it and prints a warning that the key is exposed.
The command you use is chmod. Example: chmod 644 index.html sets one file, and chmod -R 755 public sets a folder and everything inside it recursively. Be careful, the powerful -R is dangerous on mixed folders because it gives files the same number as directories. The cleaner approach is to separate them: one permission for folders and another for files, and we return to this in the storage section.
The Real Danger of 777, With an Example
When a developer hits a permission error, the first thing that sometimes jumps to mind is chmod -R 777 to make the error vanish instantly. The problem is that 777 means any process on the server, under any user, can write to and execute this file.
Picture this real scenario: a site has a file upload flaw that lets an attacker upload a malicious PHP file to the uploads folder. If the folder is 755 and owned by a different user, the upload may fail or the file may fail to execute. But if the folder is 777, the attacker uploads the malicious file, then runs it through the browser, and from there moves laterally across the server. A trivial permission mistake becomes a full breach. The rule is strict: never use 777 on a production server. If the web server needs to write to a folder, the correct fix is folder ownership by the web server's user with 755 or 775, not opening it to the entire world.
chown: Who Owns the File in the First Place
Permissions (chmod) decide what is allowed, but chown decides who the owner and group are. The syntax is chown user:group file. In web apps this is the source of half the trouble. The web server usually runs under a user like www-data on Ubuntu or nginx on other systems. If your project files are owned only by your personal account, the web server cannot write to the logs and cache folders.
| Case | Correct ownership | Permission |
|---|---|---|
| Project code (read only) | you:web-group | folders 755, files 644 |
| Writable storage folder | web-user:web-group | 775 (with group write) |
| Secret env file | you:web-group | 640 or 600 |
Common storage Permission Mistakes
In Laravel and web frameworks, the storage and bootstrap/cache folders need the web server to write into them. The most famous error is "failed to open stream: Permission denied" because these two folders are owned by your account, not the web user. The correct fix is three steps: first set ownership with chown -R $USER:www-data storage, second set folder permissions with find storage -type d -exec chmod 775 {} \;, third set files with find storage -type f -exec chmod 664 {} \;. This way the web server writes through the group, the rest of the server's users have no write access, instead of the lazy 777 fix that opens a hole.
sudo Instead of root in Daily Work
Logging in daily as root is a major operational mistake. The root account owns everything, and any wrong command it runs executes without asking. Something like rm -rf in the wrong place wipes an entire system. The correct alternative is a regular user account with sudo rights, so you work daily under a limited account, and when you need an admin command you just prefix it with sudo. This gives you three benefits: every admin command is logged with the name of who ran it, you need conscious confirmation before each dangerous action, and if your normal session is stolen the attacker does not hold root directly. On any new cloud server, the first thing you do is create a user, add them to the sudo group, then disable root login over SSH.
The Special Bits: setuid, setgid, and the sticky bit
Behind the usual three digits there is an optional fourth digit in front carrying three special permissions that solve real problems in teamwork:
- Sticky bit (number 1): placed on shared folders like /tmp, it prevents any user from deleting others' files even if the folder is world writable. You see it in ls -l as a t at the end of the folder's permission. The typical /tmp permission is 1777 for exactly this reason: writable by everyone while preventing each user from tampering with others' files.
- setgid on a folder (number 2): makes every new file created inside the folder inherit the folder's group, not the creator's group. This is the cleanest way for a folder shared by a team, ensuring everything created stays owned by the shared group and everyone can write to it.
- setuid on an executable (number 4): runs the program with its owner's privileges, not those of whoever ran it. Powerful but dangerous, since a setuid program owned by root runs with root privileges for any user who launches it. Only place it on trusted system binaries, and periodically audit for any unexpected setuid file, since it can be a breach door.
umask: The Default Permission for New Files
Why is your new file created with 644 rather than 666? Because umask subtracts permissions from the default. The common value 022 subtracts write from the group and other, so a file becomes 644 and a folder 755. If you want new files to be more closed by default, set umask to 077, so every new file becomes 600 and folders 700, readable only by their owner. This is useful on a server shared by more than one user where you want strict default privacy.
A Practical Conclusion
Do not memorize numbers, understand the model, then apply these decisions:
- Regular files 644, folders and scripts 755, secrets 600.
- Never 777 on production, replace it with correct ownership via chown.
- Writable storage folder: ownership by the web user, 775 for folders and 664 for files.
- Work under a regular account with sudo, and disable root login over SSH.
If you run a custom app that needs precise permission control and real resource isolation, the right foundation is a cloud server with resources dedicated to you alone. Check the cloud server plans and pricing and plans, the entry plan covers most mid-size apps and activates automatically within seconds after payment, from Riyadh servers at roughly 8ms latency.


