If you are a software engineer or DevOps engineer or System Administrator When working with Linux systems — whether you’re a developer, system administrator, or student — one of the most important concepts to understand is file permissions and ownership.
These permissions define who can read, write, or execute files and directories. Misconfigured permissions can lead to security risks, broken applications, or restricted access to important files.
In this guide, you’ll learn:
- What Linux file permissions are
- How to check and modify them
- The difference between symbolic and numeric (octal) modes
- How ownership and groups work
- Practical examples for web projects like Laravel
Let’s dive in.
What Are File Permissions in Linux?
Every file and directory in Linux belongs to:
- A user (owner)
- A group
- Everyone else (others)
Each of these entities can have three types of permissions:
Symbol | Permission | Meaning |
r | Read | View the file’s contents or list directory items |
w | Write | Modify or delete files |
x | Execute | Run scripts or enter directories |
Viewing File Permissions
To check the current permissions, use:
ls -l
Example output:
-rwxr-xr– 1 saymon dev 2048 Oct 9 10:00 script.sh
Let’s break it down:
Segment | Meaning |
– | Regular file (or d for directory) |
rwx | Owner permissions (read, write, execute) |
r-x | Group permissions |
r– | Others (public) permissions |
saymon | File owner |
dev | Group name |
So, script.sh can be read/written/executed by the owner, read/executed by the group, and read-only for others.
Changing Permissions with chmod
Symbolic Method
Use letters to modify permissions:
chmod u+x file.sh # Add execute for user (owner)
chmod g-w file.txt # Remove write from group
chmod o=r file.txt # Set read-only for others
Numeric (Octal) Method
Each permission has a numeric value: r = 4, w = 2, x = 1
You add these numbers for each entity (user, group, others):
Symbolic | Numeric | Description |
rwx—— | 700 | Full access for owner only |
rwxr-xr-x | 755 | Owner full, group and others read/execute |
rw-r–r– | 644 | Owner read/write, others read-only |
rwxrwxrwx | 777 | Everyone full access (insecure) |
Example:
chmod 755 script.sh
Numeric Representation Explained
Let’s understand how it’s calculated.
Permission | Binary | Decimal (Octal) |
— | 000 | 0 |
–x | 001 | 1 |
-w- | 010 | 2 |
-wx | 011 | 3 |
r– | 100 | 4 |
r-x | 101 | 5 |
rw- | 110 | 6 |
rwx | 111 | 7 |
Thus:
rwxr-xr– → Owner=7, Group=5, Others=4
chmod 754 file.txt
Managing Ownership with chown and chgrp
Each file in Linux also has:
- An owner (user)
- A group
To change them:
sudo chown username file.txt # Change owner
sudo chown :groupname file.txt # Change group
sudo chown username:groupname file.txt # Change both
To apply recursively:
sudo chown -R www-data:www-data /var/www/html/project
To change only the group:
sudo chgrp devs file.txt
Directory Permissions
Directories use permissions slightly differently:
Permission | Effect |
r | Allows listing files in the directory |
w | Allows creating or deleting files |
x | Allows entering (cd) into the directory |
Example:
chmod 755 /var/www
This allows everyone to enter and list files, but only the owner can modify them.
Special Permission Bits (Advanced)
Linux supports three special bits:
Name | Symbol | Octal | Purpose |
SetUID | s | 4xxx | Runs program as file’s owner |
SetGID | s | 2xxx | Runs program as group owner |
Sticky Bit | t | 1xxx | Only file owner can delete in a shared directory |
Example:
chmod 4755 file # SetUID
chmod 2755 dir # SetGID
chmod 1777 /tmp # Sticky bit (for shared temp directories)
Practical Example — Laravel or Web Projects
When deploying Laravel on a shared hosting (e.g., Hostinger or cPanel):
sudo chown -R www-data:www-data /var/www/html/project
sudo chmod -R 755 /var/www/html/project
sudo chmod -R 775 /var/www/html/project/storage
sudo chmod -R 775 /var/www/html/project/bootstrap/cache
Explanation:
- The web server (Apache/Nginx) user (www-data) owns the files
- All directories are executable so they can be accessed
- storage and cache are writable by the server
Summary — Linux Permissions & Ownership Cheat Sheet
Command | Description |
ls -l | Show file permissions |
chmod | Change file permissions |
chown | Change file owner and group |
chgrp | Change group ownership |
-R | Apply changes recursively |
umask | Set default permissions for new files |
Common Permission Modes:
Mode | Meaning |
644 | Readable by everyone, writable by owner |
755 | Executable for everyone, writable by owner |
700 | Only owner has access |
777 | Everyone can read/write/execute (unsafe) |
Linux file permissions and ownership are at the heart of its security and stability.
By mastering chmod, chown, and chgrp, you gain full control over your system — deciding exactly who can do what.
Always remember:
- Never use 777 unless absolutely necessary.
- Use 755 for directories and scripts, 644 for text/config files.
- Secure ownership with chown and use groups wisely.
Once you understand these fundamentals, managing Linux servers, hosting Laravel apps, or configuring web directories becomes a breeze.
Keywords: Linux file permissions, chmod command, chown, file ownership, Linux security, numeric permissions, chmod 755, Linux tutorial