How to Change File Permissions Using chmod in Linux
Welcome to Program Guru. In this tutorial, we’re going to learn how to change file permissions using the chmod command in Linux.
If you're new to Linux, don't worry! We'll go step-by-step, and by the end of this lesson, you'll be confident in managing file permissions like a pro.
🔐 What Are File Permissions?
In Linux, every file and folder has permissions that determine who can read, write, or execute it. These permissions are categorized by:
- Owner – the person who created the file
- Group – a set of users who share access
- Others – everyone else
📋 Check Current Permissions
Let’s check the permissions of a file using the ls -l command:
ls -l myscript.sh
-rw-r--r-- 1 user user 123 Jul 2 10:00 myscript.sh
This tells us:
rw-— Owner can read and writer--— Group can readr--— Others can read
🛠 Using chmod to Change Permissions
▶ Symbolic Mode
Let's say you want to give execute permission to the owner:
chmod u+x myscript.sh
ls -l myscript.sh
-rwxr--r-- 1 user user 123 Jul 2 10:00 myscript.sh
What we did:
u= user (owner)+= add permissionx= execute
▶ Numeric Mode
You can also use numbers to set all permissions at once:
chmod 755 myscript.sh
ls -l myscript.sh
-rwxr-xr-x 1 user user 123 Jul 2 10:00 myscript.sh
This means:
7= read + write + execute (owner)5= read + execute (group)5= read + execute (others)
🧪 Examples for Practice
Make a file readable and writable only by the owner:
chmod 600 secrets.txt
Make a script executable by everyone:
chmod a+x deploy.sh
Remove write permission from group:
chmod g-w report.txt
✅ Verify Your Changes
Always check your work:
ls -l
🎯 Summary
So now you know:
- How to view file permissions
- How to use
chmodin symbolic and numeric modes - How to verify your changes with
ls -l
Managing file permissions is a core skill in Linux. Practice often and you’ll master it in no time!
Thanks for learning with Program Guru. Happy coding!
