Day-4 Script Execution Permissions
Hello, I'm Ramya! 👩💻 I'm a passionate tech enthusiast on a journey to build a thriving career in Cloud Computing and DevOps. 🌩️⚙️ I strongly believe in learning through mistakes and growing together as a community. 🌱 By documenting my tech journey, I aim to track my personal and professional growth while inspiring others to embrace their learning paths. Let’s connect, share, and grow in this ever-evolving world of technology! 🚀
Introduction
In Linux, not all files are created equal — some are just data, while others are scripts or programs that you can run.
Before a script can be executed, it needs the right permissions.
In this guide, we’ll explore:
How Linux handles execution permissions
How to grant or revoke execution rights
Best practices for secure script execution
📂 Understanding Linux File Permissions
Every file in Linux has three sets of permissions:
Owner (user)
Group
Others (everyone else)
Each set can have:
r→ Readw→ Writex→ Execute
You can see permissions with:
ls -l script.sh
Example:
-rwxr-xr-- 1 ramya devs 1024 Aug 9 15:12 script.sh
Here:
rwx→ Owner can read, write, executer-x→ Group can read and executer--→ Others can read only
🚀 Giving Execute Permissions to a Script
1️⃣ Using chmod
The chmod command changes file permissions.
Give execute permission to the owner:
chmod u+x script.sh
Give execute permission to everyone:
chmod +x script.sh
Remove execute permission from others:
chmod o-x script.sh
2️⃣ Using Numeric Permissions
Linux also supports octal (numeric) permission notation.
| Permission | Value |
| Read (r) | 4 |
| Write (w) | 2 |
| Execute (x) | 1 |
Example:
Owner = 7 (read + write + execute), Group = 5 (read + execute), Others = 5 (read + execute):
chmod 755 script.sh
🔍 Running a Script
Once executable, you can run it in two ways:
Directly (requires x permission):
./script.sh
Using an interpreter (does not require x permission):
bash script.sh
python3 script.py
Even without
chmod +x, you can run a script if you call it through its interpreter.
⚠️ Security Best Practices
Avoid
chmod 777→ This gives full permissions to everyone and is a security risk.Limit to necessary users → Use
chmod 700for private scripts.Use proper ownership → Ensure scripts belong to the correct user (
chowncommand).Validate content → Never execute scripts from untrusted sources.