Permissions and sudo

Welcome back.
In the previous lesson, you learned how to read files and search inside them.
Now we enter the part where Linux starts saying:
“Permission denied.”
Do not take it personally.
Linux is not angry.
Linux is just protecting the system from chaos, mistakes, and sleepy fingers with administrator power.
What You’ll Learn
In this lesson, you’ll learn:
- what file permissions are;
- how to read permission symbols like
rwx; - what users, groups, and others mean;
- how to check your current user with
whoami; - how to use
chmod; - what
sudodoes; - why you should not use
sudolike hot sauce.
The Mission
Your mission is simple:
Understand why some files can be read, changed, or executed — and why some files politely refuse your requests like a serious security guard at the door.
Check Who You Are
First, check your current user:
whoami
You may see something like:
viktor
This means you are working as the user viktor.
You are not root.
That is good.
Being root all the time is like driving a tank to buy bread.
Possible, but unnecessary and slightly worrying.
Create a Practice File
Go to your practice folder:
cd ~/terminal-practice
If it does not exist, create it:
mkdir -p ~/terminal-practice
cd ~/terminal-practice
Create a file:
touch permissions-demo.txt
Now list it with details:
ls -l permissions-demo.txt
You may see something like:
-rw-r--r-- 1 viktor viktor 0 May 2 10:00 permissions-demo.txt
This looks scary at first.
But it is not magic.
It is just information wearing a serious jacket.
Understanding Permission Symbols
Look at this part:
-rw-r--r--
The first character tells the file type:
- means regular file
d means directory
Then permissions are grouped like this:
rw- r-- r--
These groups mean:
user group others
So:
rw- the owner can read and write
r-- the group can only read
r-- others can only read
Linux is basically saying:
“The owner can edit this. Everyone else can look, but keep their hands in their pockets.”
What r, w, and x Mean
Permissions use three letters:
r = read
w = write
x = execute
For files:
rmeans you can read the file;wmeans you can change the file;xmeans you can run the file as a program or script.
For directories:
rmeans you can list the directory;wmeans you can create or delete files inside;xmeans you can enter the directory.
Yes, x on a directory means “enter”.
Linux likes to keep life interesting.
Add Text to the File
Write something into the file:
echo "Permissions are important." > permissions-demo.txt
Read it:
cat permissions-demo.txt
You should see:
Permissions are important.
So far, everything works.
The file belongs to you, and you can write to it.
Remove Write Permission
Now remove your own write permission:
chmod u-w permissions-demo.txt
Check:
ls -l permissions-demo.txt
You may see:
-r--r--r-- 1 viktor viktor 28 May 2 10:00 permissions-demo.txt
Now try to write to it again:
echo "Trying to write again." > permissions-demo.txt
You may get:
Permission denied
Good.
Linux just protected the file from changes.
Even from you.
A little rude, but technically correct.
Add Write Permission Back
Give yourself write permission again:
chmod u+w permissions-demo.txt
Now try:
echo "Writing works again." > permissions-demo.txt
cat permissions-demo.txt
You should see:
Writing works again.
Congratulations.
You removed a permission, broke your own access, and fixed it.
This is basically Linux training in miniature.
Making a Script Executable
Create a small script:
echo 'echo "Hello from my script!"' > hello.sh
Try to run it:
./hello.sh
You may see:
Permission denied
Why?
Because the file is not executable yet.
Add execute permission:
chmod u+x hello.sh
Now run it:
./hello.sh
You should see:
Hello from my script!
That is what x does.
It tells Linux:
“This file is allowed to run.”
Numeric Permissions
You may see commands like this:
chmod 755 hello.sh
This is numeric permission style.
The numbers mean:
7 = read + write + execute
5 = read + execute
5 = read + execute
So 755 means:
owner can read, write, execute
group can read and execute
others can read and execute
Another common one:
chmod 644 permissions-demo.txt
This means:
owner can read and write
group can read
others can read
For now, remember:
644is common for normal files;755is common for scripts and directories.
Do not memorize everything today.
Your brain is not a USB stick.
What Is sudo?
sudo means “run this command with administrator privileges”.
Example:
sudo pacman -S htop
On Ubuntu or Debian:
sudo apt install htop
On Fedora:
sudo dnf install htop
sudo is used when a command needs higher privileges.
For example:
- installing software;
- changing system files;
- restarting services;
- editing protected configuration.
sudo is powerful.
Do not use it automatically.
Using sudo everywhere is like opening every door with a chainsaw.
Effective, but not elegant.
Common Permission Error
You may see:
Permission denied
This usually means:
- you do not have permission to read the file;
- you do not have permission to write to the file;
- you do not have permission to execute the file;
- you are trying to change something owned by another user or by root.
Before using sudo, ask:
Do I really need administrator power here?
Sometimes the answer is yes.
Sometimes the answer is: “No, Viktor, you are just in the wrong folder.”
Be Careful with sudo
This is dangerous:
sudo rm -r /some/system/folder
This can delete important system files.
Linux will do exactly what you ask.
Not what you meant.
That is the difference between a computer and a wise friend.
Practice
Try this:
cd ~/terminal-practice
touch permission-test.txt
ls -l permission-test.txt
chmod u-w permission-test.txt
ls -l permission-test.txt
chmod u+w permission-test.txt
ls -l permission-test.txt
echo 'echo "Script works!"' > test-script.sh
chmod u+x test-script.sh
./test-script.sh
Then answer:
- What does
whoamishow? - What does
chmod u-wdo? - What does
chmod u+wdo? - What does
chmod u+xdo? - What does
sudoallow you to do?
Mini Challenge
Create a script called my-info.sh.
It should print:
Hello from Linux!
Today I am learning permissions.
Then:
- Create the file.
- Try to run it.
- Add execute permission.
- Run it again.
- Check permissions with
ls -l.
Use only terminal commands.
No mouse.
The mouse has now filed a complaint with HR.
Summary
Today you learned:
- Linux uses permissions to protect files and directories;
rmeans read;wmeans write;xmeans execute;- permissions are divided into user, group, and others;
ls -lshows permissions;chmodchanges permissions;sudoruns commands with administrator privileges;sudoshould be used carefully.
Permissions may look strange at first, but they are one of the reasons Linux is powerful and safe.
Linux says “no” not because it hates you.
It says “no” because sometimes you are one command away from creating a very educational disaster.
Next Lesson
In the next lesson, we’ll learn how to install software from the terminal using package managers.
That is where Linux becomes very convenient.
And where Arch Linux users begin to smile mysteriously.