File Permissions in Linux
1. Introduction
File permissions in Linux define who can access a file or directory and what actions they can perform. Permissions are a core part of Linux security and protect the system from unauthorized access and accidental damage.
Linux uses a permission-based access control system for files and directories.
2. Why File Permissions are Needed
- Protect files from unauthorized users
- Prevent accidental deletion or modification
- Support multi-user environments
- Maintain system security and stability
3. Permission Categories (Who can access)
Linux divides users into three categories:
| Category | Symbol | Description |
|---|---|---|
| Owner | u | User who owns the file |
| Group | g | Users in the same group |
| Others | o | All other users |
4. Permission Types (What actions are allowed)
| Permission | Symbol | Meaning (File) | Meaning (Directory) |
|---|---|---|---|
| Read | r | View file content | List directory |
| Write | w | Modify file | Create/delete files |
| Execute | x | Run file | Access directory |
5. Viewing File Permissions
Use:
ls -l
Example output:
-rwxr-xr--
Permission Breakdown
- rwx r-x r--
| | | |
| Owner Group Others
|
File type
6. File Types (First Character)
| Symbol | File Type |
|---|---|
- | Regular file |
d | Directory |
l | Symbolic link |
c | Character device |
b | Block device |
7. Changing Permissions – chmod
1. Symbolic Mode
chmod u+x file.txt
chmod g-w file.txt
chmod o+r file.txt
chmod u+rwx,g+rx,o-r file.txt
2. Numeric (Octal) Mode
| Value | Permission |
|---|---|
| 4 | Read |
| 2 | Write |
| 1 | Execute |
Examples:
chmod 755 file.sh
chmod 644 file.txt
Meaning:
7→ rwx6→ rw-5→ r-x4→ r–
8. Changing Ownership – chown
chown user file.txt
chown user:group file.txt
9. Special Permissions (Advanced – Exam Important)
1. SUID (Set User ID)
- Executes file with owner’s permission
- Symbol:
s
chmod u+s file
2. SGID (Set Group ID)
- Executes with group permission
- New files inherit group
chmod g+s directory
3. Sticky Bit
- Only owner can delete files in directory
- Used in
/tmp
chmod +t directory
10. Permissions on Directories (Key Difference)
r→ list filesw→ create/delete filesx→ enter directory
📌 Execute permission is mandatory to access a directory.
11. Default Permissions & umask
umasksets default permissions
umask
Example:
- umask =
022 - File permission →
644 - Directory permission →
755
12. Real-World Example
ls -l /etc/passwd
- Readable by all
- Writable only by root
13. Security Best Practices
- Avoid
777permissions - Use
sudocarefully - Assign minimum required permissions
- Use groups efficiently
14. File Permissions Summary Table
| Command | Purpose |
|---|---|
ls -l | View permissions |
chmod | Change permissions |
chown | Change owner |
umask | Default permissions |
15. Conclusion
File permissions are a fundamental security mechanism in Linux. By controlling access at the file and directory level, Linux ensures safe, stable, and multi-user operation, making it ideal for servers and enterprise systems.
