File Permissions Review — Securing Files and Directories in Linux¶
File Permissions are one of the most important security mechanisms in Linux. They determine who can read, write, or execute files and directories, preventing unauthorized access and protecting sensitive system resources. Incorrect permissions can expose confidential data, allow unauthorized modifications, or even lead to privilege escalation. Every Linux administrator, DevOps engineer, Cloud Architect, Platform Engineer, and Site Reliability Engineer (SRE) must understand how to review, audit, and manage Linux file permissions effectively.
Learning Path¶
Course Progress
What You'll Learn¶
After completing this lesson, you'll be able to:
- Review the Linux permission model
- Understand ownership and groups
- Interpret symbolic and numeric permissions
- Configure file permissions securely
- Understand special permissions
- Audit file permissions
- Identify insecure permissions
- Apply production security best practices
Prerequisites¶
Complete:
- Modules 1–10
- Module 11 Lesson 1 – SSH Hardening
Why Review File Permissions?¶
Imagine a configuration file containing database passwords.
Incorrect permissions:
Anyone can read or modify the file.
Secure permissions:
Only the owner has access.
Proper permissions protect systems from unauthorized access and accidental changes.
Linux Permission Model¶
Every file and directory has:
- Owner
- Group
- Others
Each category has its own permissions.
Viewing Permissions¶
Use:
Example:
Understanding Permission Fields¶
Example:
Breakdown:
Permission Types¶
| Symbol | Meaning |
|---|---|
r | Read |
w | Write |
x | Execute |
- | Permission not granted |
Read Permission¶
For files:
For directories:
Write Permission¶
For files:
For directories:
Execute Permission¶
For files:
For directories:
Numeric Permissions¶
Each permission has a numeric value.
| Permission | Value |
|---|---|
| Read | 4 |
| Write | 2 |
| Execute | 1 |
Examples:
Common Permission Values¶
| Permission | Numeric |
|---|---|
| rwxrwxrwx | 777 |
| rwxr-xr-x | 755 |
| rw-r--r-- | 644 |
| rw------- | 600 |
| rwxr----- | 740 |
Changing Permissions¶
Use:
Example:
Symbolic mode:
Changing Ownership¶
Use:
Change owner and group.
Changing Group¶
Use:
Special Permissions¶
Linux supports three special permissions.
- SUID
- SGID
- Sticky Bit
SUID¶
Numeric:
Example:
Displayed as:
The program runs with the permissions of its owner.
SGID¶
Numeric:
Example:
Displayed as:
Files created inside a directory inherit the directory's group ownership.
Sticky Bit¶
Numeric:
Example:
Displayed as:
Users can delete only their own files within the directory.
Example:
Finding World-Writable Files¶
Search:
These files should be reviewed carefully.
Finding SUID Files¶
Review regularly.
Finding SGID Files¶
Secure File Permissions¶
Examples:
Private SSH key:
SSH directory:
Shell script:
Configuration file:
Common Commands¶
View permissions.
Change permissions.
Change owner.
Change group.
Search SUID files.
Real Production Examples¶
Secure SSH key.
Secure SSH directory.
Secure configuration.
Assign ownership.
Production Perspective¶
Permission management is essential for:
- Linux servers
- Cloud virtual machines
- Kubernetes nodes
- Application servers
- Database servers
- Shared storage
- CI/CD environments
- Enterprise security compliance
Regular permission reviews reduce the risk of unauthorized access and privilege escalation.
Hands-on Lab¶
Task 1¶
View file permissions.
Task 2¶
Create a file.
Task 3¶
Assign secure permissions.
Task 4¶
Create an executable script.
Task 5¶
Change ownership.
Task 6¶
Search for SUID files.
Task 7¶
Search for world-writable files.
Task 8¶
Review the permissions of your ~/.ssh directory.
Command Deep Dive¶
| Command | Purpose | Production Example |
|---|---|---|
ls -l | View permissions | Security auditing |
chmod | Modify permissions | Access control |
chown | Change ownership | User management |
chgrp | Change group | Shared access |
find | Locate insecure files | Security audits |
stat | Display detailed file metadata | Permission verification |
Common Permission Mistakes¶
| Mistake | Solution |
|---|---|
Using 777 unnecessarily | Apply the principle of least privilege |
| Incorrect file ownership | Assign the correct owner and group |
| World-writable configuration files | Restrict permissions |
| Public SSH private keys | Set permissions to 600 |
| Ignoring SUID files | Audit them regularly |
Production Troubleshooting Scenario¶
Scenario
A web application stores database credentials in a configuration file.
Permissions:
Any user can modify or read the file.
Secure configuration:
Result:
- Only the application owner can modify the file.
- Group members can read it if necessary.
- Other users have no access.
Best Practices¶
- Follow the principle of least privilege.
- Avoid
777permissions unless absolutely necessary. - Assign correct file ownership.
- Protect SSH keys with
600permissions. - Audit SUID and SGID files regularly.
- Remove unnecessary execute permissions.
- Review file permissions during security audits.
Common Mistakes¶
❌ Assigning 777 permissions to application files.
✅ Avoid this mistake: assigning 777 permissions to application files.
❌ Leaving SSH private keys publicly readable.
✅ Do not leave SSH private keys publicly readable.
❌ Ignoring file ownership.
✅ Always review file ownership.
❌ Giving execute permission to non-executable files.
✅ Avoid this mistake: giving execute permission to non-executable files.
❌ Never reviewing permission changes.
✅ Always reviewing permission changes.
Interview Questions¶
Beginner¶
- What do
r,w, andxrepresent? - What does permission
755mean? - Which command changes file permissions?
- Which command changes file ownership?
Intermediate¶
- What is the difference between
chmodandchown? - What are SUID, SGID, and the Sticky Bit?
- Why should SSH private keys have
600permissions? - How do you find world-writable files?
Architect Level¶
- How would you audit file permissions across hundreds of Linux servers?
- How would you implement the principle of least privilege in an enterprise environment?
- What file permission controls would you enforce for production applications?
Summary¶
In this lesson, you learned:
- Linux permission model
- Ownership and groups
- Numeric and symbolic permissions
- Special permissions
- File ownership
- Permission auditing
- Secure permission practices
- Production security best practices
Proper file permissions are a fundamental layer of Linux security. Reviewing and maintaining correct ownership and permissions helps protect sensitive data, prevents unauthorized access, and reduces the risk of privilege escalation or accidental modifications.
Key Takeaways¶
- Every Linux file has an owner, group, and permission set.
- Use the principle of least privilege.
- Avoid overly permissive settings such as
777. - Protect SSH keys and sensitive files with restrictive permissions.
- Audit SUID, SGID, and world-writable files regularly.
- Review permissions as part of routine security maintenance.
What's Next?¶
Firewall (UFW) — Securing Linux Network Access
You'll explore:
- Firewall fundamentals
- Installing and enabling UFW
- Allowing and denying traffic
- Opening specific ports
- Managing application profiles
- Viewing firewall rules
- Production firewall best practices
By the end of the lesson, you'll be able to configure and manage UFW to secure Linux systems by controlling inbound and outbound network traffic.