Have you ever seen the message “Permission denied” in your Linux terminal and didn’t know what to do?
I have. And honestly, it was frustrating. I just wanted to open a file or run a command, but Linux told me no. If you’ve run into this too, don’t worry. In this post, I’ll show you how to fix it in simple steps — even if you’re still new to Linux.
What Does “Permission Denied” Mean?
In Linux, permissions control who can read, write, or run files.
The “Permission denied” error means that your user account is trying to do something it doesn’t have permission to do. It’s kind of like trying to open a locked door without the key.
Linux has three basic types of permissions:
- Read (r) – You can view the file.
- Write (w) – You can edit or delete the file.
- Execute (x) – You can run the file like a program or script.
Permissions are set for three types of users:
- Owner – The person who created the file.
- Group – A set of users with shared access.
- Others – Everyone else.
A Simple Example
Let’s say you run this:
./install.sh
And you get:
bash: ./install.sh: Permission denied
This usually means the file is not marked as executable. I’ll show you how to fix that soon.
Why You Might See This Error
Here are the most common reasons I’ve seen:
- You don’t own the file.
- The file is not executable.
- You’re trying to access a folder without the right permissions.
- You need to use
sudo
(superuser). - A script has the wrong permissions set.
Have you seen one of these before?
Let’s walk through how to check and fix each one.
Step 1: Check File Permissions
Use the ls -l
command to see file details:
ls -l filename
You’ll see something like:
-rw-r--r-- 1 user user 1234 May 1 10:00 filename
Let’s break that down:
- The first part (
-rw-r--r--
) shows the permissions. - The first
user
is the owner. - The second
user
is the group.
In this example:
- The owner can read and write.
- The group can only read.
- Others can only read.
If you’re trying to run the file and don’t see an x
(for execute), that’s your problem.
Step 2: Make the File Executable
If you’re trying to run a script or program, but get “Permission denied,” try this:
chmod +x filename
This gives execute permission to the file.
Try again:
./filename
Did it work? That’s usually the fix for scripts or installer files.
Step 3: Use sudo
If You Need Root Access
Sometimes, the error means you’re trying to do something that only the root user (the admin) can do. For example:
cp file.txt /etc/
If you see “Permission denied,” try using sudo
:
sudo cp file.txt /etc/
The sudo
command means “do this as the superuser.”
You’ll be asked for your password the first time.
Be careful with sudo. It can change important system files. Only use it when you’re sure you need it.
Step 4: Change File Owner (If Needed)
Let’s say you copied a file from another user, or from a USB drive. You may not own the file.
Check ownership:
ls -l filename
If your username isn’t listed, change it:
sudo chown yourname:yourname filename
Replace yourname
with your actual username.
Now try your command again.
Step 5: Check Folder Permissions
Sometimes, it’s not the file — it’s the folder. If you don’t have permission to enter or write to a folder, you’ll see “Permission denied.”
You can check folder permissions like this:
ls -ld foldername
If you see something like drwx------
, and you’re not the owner, you’ll need to either:
- Use
sudo
if needed - Ask the owner to give you access
- Or use
chmod
andchown
(with caution)
What Is chmod
and How Does It Work?
chmod
changes permissions.
Here’s a simple list of what each letter means:
r
= read (4)w
= write (2)x
= execute (1)
You can combine these:
7
= read + write + execute6
= read + write5
= read + execute4
= read only
To give full permissions to the owner, and read-only to others:
chmod 744 filename
That means:
- Owner: 7 = rwx
- Group: 4 = r
- Others: 4 = r
Want to remove all permissions?
chmod 000 filename
Want to make a script executable by everyone?
chmod 755 script.sh
Two Helpful Lists
When You Might Need to Fix Permissions:
- You copied a file from another user.
- You’re installing software.
- You’re writing to a protected folder.
- You downloaded a file that’s not executable.
- You’re editing system settings or logs.
Common Permission Fix Commands:
chmod +x file
– make it executablesudo command
– run as adminchown user:user file
– change ownerls -l
– check permissionsls -ld
– check folder permissions
A Personal Tip
When I started using Linux, I often got stuck on permission errors. I didn’t know what to look for. But after learning about chmod
, chown
, and sudo
, everything made more sense.
Now, when I see “Permission denied,” I ask myself:
- Am I the owner?
- Do I need to make the file executable?
- Am I working in a protected folder?
Try asking yourself the same questions. You’ll solve the issue faster.
What Not to Do
Here’s a warning.
Some people use:
chmod 777 filename
This gives everyone full permission. It works, but it’s not safe. Anyone could edit or delete that file. I only use 777 in special cases, like temporary testing on local machines — never on servers.
Summary
You’ve just learned:
- What “Permission denied” means
- How to check file and folder permissions
- How to fix them using
chmod
,chown
, andsudo
- When and why to use each method
Linux may seem strict with permissions, but that’s what keeps it safe. With just a few commands, you can fix most permission errors yourself.
Next time you get stuck, don’t panic. Just take a look at the file, check its permissions, and apply what you’ve learned here.
Have you fixed a permission error today?
Let me know how it went, or what kind of error you’re facing — I’d be happy to help.