Permission Denied! Or Not? A Hands-On Guide to Linux File Access


If you’ve ever tried to run or open a file in Linux and been greeted with the dreaded "Permission Denied", you’re not alone. Linux file permissions are powerful and secure — but also confusing if you’re new.
You might be wondering:
- Why can’t I open this file?
- What does
-rwxr--r--
even mean? - How do I give myself or others access safely?
The truth is, Linux file access isn’t magic — it’s just misunderstood.
In this hands-on guide, we’ll walk you through everything you need to know about Linux file permissions — from basic concepts to real-world fixes. Whether you're a new Linux user or just tired of running sudo
every time something breaks, this guide is your shortcut to clarity and control.
By the end, you’ll learn:
- What Linux permissions are and why they exist
- How to read permission strings (like
-rw-r--r--
) - The difference between users, groups, and others
- How to safely change access using
chmod
,chown
, andls -l
- How to troubleshoot and fix common permission issues
No more guessing. No more trial and error.
Let’s break it down — once and for all.
What Are Linux File Permissions?
In Linux, every file and directory has rules that control who can read, write, or run it.
These rules are called permissions, and they apply to three kinds of users:
User Type | Meaning |
---|---|
Owner | The person who created the file |
Group | Other users who belong to the same group |
Others | Everyone else on the system |
And every user type has three kinds of permissions:
Permission | Symbol | What It Allows |
---|---|---|
Read | r | View contents or list files |
Write | w | Modify contents or structure |
Execute | x | Run files or access folders |
Viewing File Permissions
You can see the permissions of any file using the ls -l
command:
ls -l myfile.txt
Sample output:
-rw-r--r-- 1 mustaf users 120 Jul 23 08:00 myfile.txt
Here’s what it means:
-rw-r--r--
→ Permissions1
→ Number of hard linksmustaf
→ Owner (user)users
→ Group120
→ File size in bytesJul 23 08:00
→ Last modified timemyfile.txt
→ File name
Breakdown of -rw-r--r--
This 10-character string represents the file type and permissions.
Part | Symbol | Meaning |
---|---|---|
Type | - | This is a regular file (d would mean directory) |
Owner | rw- | Owner can read and write (but not execute) |
Group | r-- | Group can read only |
Others | r-- | Others (everyone else) can read only |
Tip: A dash -
in any of the rwx
positions means that permission is not granted for that user category.
So -rw-r--r--
means:
- It’s a file
- The owner can read & write
- The group can read
- Everyone else can read
Understanding Permission Values (Octal System)
Linux permissions can also be represented numerically using the octal system:
Symbolic | Binary | Octal | Meaning |
---|---|---|---|
rwx | 111 | 7 | read, write, execute |
rw- | 110 | 6 | read, write |
r-x | 101 | 5 | read, execute |
r-- | 100 | 4 | read only |
-wx | 011 | 3 | write, execute |
-w- | 010 | 2 | write only |
--x | 001 | 1 | execute only |
--- | 000 | 0 | no permission |
So a permission like 755
means:
- 7 = rwx (Owner can do everything)
- 5 = r-x (Group can read & execute)
- 5 = r-x (Others can read & execute)
How to Change Permissions
Use the chmod
command:
chmod 755 myfile.sh
That gives:
- Full access to the owner
- Read + execute for group and others
Common Examples:
Command | Description |
---|---|
chmod 777 file | Everyone can read/write/execute (⚠️ risky) |
chmod 644 file | Owner can read/write, others read-only |
chmod +x script.sh | Add execute permission to a script |
Ownership: Who Owns the File?
Each file has:
- An owner
- A group
View ownership using ls -l
:
ls -l myfile.txt
Change ownership using chown
:
sudo chown username:group myfile.txt
Example:
sudo chown mustaf:developers myscript.sh
Hands-On Practice
Let’s practice together.
1. Create a new file
touch demo.txt
2. View its permissions
ls -l demo.txt
You’ll likely see:
-rw-r--r-- 1 youruser yourgroup 0 Jul 23 10:10 demo.txt
3. Try to make it executable
./demo.txt
Result:
bash: ./demo.txt: Permission denied
4. Add execute permission
chmod +x demo.txt
./demo.txt
Still no output? That’s because it’s an empty file. Let’s add content:
echo 'echo Hello, world!' > hello.sh
chmod +x hello.sh
./hello.sh
Output:
Hello, world!
Success ✅
Directory Permissions
Directories need execute (x
) permission to access or list files inside.
Try this:
mkdir secret
touch secret/hidden.txt
chmod 000 secret
ls secret
Output:
ls: cannot open directory 'secret': Permission denied
Now fix it:
chmod 755 secret
ls secret
Special Permission Bits (Advanced Tip)
Special Bit | Use Case |
---|---|
suid | Run as file owner |
sgid | Run with group’s rights |
sticky | Only owner can delete (used in /tmp ) |
Not required for beginners, but useful later.
Summary: Commands You Should Know
Command | What It Does |
---|---|
ls -l | View file permissions |
chmod 755 file | Change permissions using octal |
chmod +x file | Add execute permission |
chown user:group file | Change ownership |
whoami | Show current user |
groups | Show your groups |
Final Tips for Beginners
- Don’t use
chmod 777
unless absolutely necessary. - Avoid using
sudo
unless the file is truly protected. - Use
ls -ld folder/
to see directory permissions. - Practice with dummy files — experiment safely.
You're Now a Linux Permission Ninja!
With this guide, you now understand:
- File vs folder permissions
- The difference between owner, group, others
- Symbolic and numeric permission modes
- How to fix "Permission denied" confidently
Next time Linux throws you a permission error, smile — because you know what to do.