Hi everyone. The most common way people meet the chmod command is through an error. You write a small script, try to run it, and the terminal answers with Permission denied. In this guide I reproduce exactly that on Ubuntu 26.04, fix it, and then use the same lab to show the other ways chmod is used: symbolic mode, numeric mode like 600 and 755, changing a whole folder with -R, and the case where even chmod itself is refused.
If the rwx letters or numbers like 664 are still unclear, the previous guide on Linux file permissions explains how to read them. Here we focus on changing them.
Distro : Ubuntu 26.04.1 LTS (Desktop)
Folder : ~/chmod-lab
Script : backup.shFixing Permission Denied on a Script
Write a script and try to run it

I created a two-line script called backup.sh and checked its content with cat.
printf '%s\n' '#!/bin/bash' 'echo Backup started' > backup.sh
cat backup.sh
./backup.sh
ls -l backup.shRunning it gave bash: ./backup.sh: Permission denied (number 1). The script is fine. The problem is in the permission string, -rw-rw-r– (number 2): there is no x anywhere, so Linux will not execute the file for anyone, not even its owner.
My experience: My first attempt at this lab used printf with a date format inside the text, and printf treated the percent signs as its own placeholders and cut the script short. If you build a file with printf, keep the content in separate arguments after ‘%s\n’ as shown above, or simply write the script in a text editor.
Add execute permission with chmod +x

chmod +x backup.sh
ls -l backup.sh
./backup.shAfter chmod +x the string becomes -rwxrwxr-x and the name turns green in ls (number 1), which is how the terminal marks executable files. This time the script runs and prints Backup started (number 2).
Notice that +x without anything in front of it added x for the owner, the group, and others at once. That is often more than you want, which is where the next two styles come in.
Symbolic Mode: Say Exactly Who Gets What
Set permissions with u, g, and o

chmod u=rwx,g=rx,o= backup.sh
stat -c '%A %a %n' backup.shIn symbolic mode, u is the owner, g is the group, and o is others. The = sign sets the permissions exactly, so this command gives the owner everything, the group read and execute, and others nothing at all (number 1). The result is -rwxr-x—, which stat also shows as 750 (number 2).
You can also use + and – to change one thing without touching the rest. For example chmod g-w removes write from the group and leaves every other bit as it was.
Numeric Mode: 600 and 755
Protect a private file and publish a script

Numbers are faster once you know the pattern: r is 4, w is 2, x is 1, and each digit covers owner, group, and others in that order.
echo salary list > secret.txt
chmod 600 secret.txt
chmod 755 backup.sh
stat -c '%A %a %n' secret.txt backup.sh600 means only the owner can read and write, so secret.txt becomes -rw——- (number 1). This is the usual setting for anything private, like SSH keys or files with passwords. 755 gives the owner full control and lets everyone else read and run the file, so backup.sh is now -rwxr-xr-x (number 2), the common setting for scripts and programs that others may use.
Warning: It is tempting to fix every permission problem with chmod 777. It works, but it also gives every user on the system the right to change or delete the file. Find which bit is actually missing and add only that.
When chmod Itself Is Refused
Change permissions on a file you do not own

Only the owner of a file, or root, may change its permissions. To show this I created a file as root inside the lab folder.
sudo touch root-file.txt
ls -l root-file.txt
chmod g+w root-file.txt
sudo chmod g+w root-file.txt
ls -l root-file.txtThe file belongs to root and the group root (number 1). Even though it sits in my own folder, chmod g+w fails with Operation not permitted (number 2). Running the same command with sudo works, and the group now has write access, -rw-rw-r– (number 3). If you are on a shared machine and do not have sudo, the fix is to ask the owner, not to keep trying.
Changing a Whole Folder with -R
Remove access for others recursively

mkdir -p project/src && touch project/src/app.py project/README.md
chmod -R o-rwx project
ls -lR projectThe -R option applies chmod to the folder and everything inside it (number 1). Here o-rwx takes every permission away from others, and both the files and the src folder show three dashes at the end (number 2 and 3).
Note: Be careful with -R and execute bits. Running something like chmod -R 644 on a folder also removes x from every subfolder, and folders without x can no longer be opened. When folders and files need different numbers, use find to target each type separately.
Common Problems and How to Fix Them
Permission denied when running a script
The file has no x for you. Run chmod +x on it, or chmod u+x if only you should run it. Also check the first line of the script, because a missing or wrong #! line causes a different kind of failure.
Operation not permitted
You are not the owner of the file. Use sudo if you administer the machine, or ask the owner to change it.
A folder cannot be opened after chmod -R
A numeric mode without x was applied to folders too. Give folders their x back, for example chmod -R u+X folder, where the capital X adds execute only to folders and files that already had it for someone.
The script runs but prints nothing or errors
chmod only controls whether a file may run, not whether it is correct. Use cat to check what is actually in the file.
That is chmod in practice: +x to make a script runnable, symbolic mode when you want to be precise, numbers like 600 and 755 for the usual cases, sudo when the file is not yours, and -R with care. Next in the series is chown, which changes who owns a file instead of what they can do with it. If chmod gives you an error I did not cover here, share the exact message in the comments.












