Skip to content
Home » File Permissions

File Permissions

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:

CategorySymbolDescription
OwneruUser who owns the file
GroupgUsers in the same group
OthersoAll other users

4. Permission Types (What actions are allowed)

PermissionSymbolMeaning (File)Meaning (Directory)
ReadrView file contentList directory
WritewModify fileCreate/delete files
ExecutexRun fileAccess 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)

SymbolFile Type
-Regular file
dDirectory
lSymbolic link
cCharacter device
bBlock 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

ValuePermission
4Read
2Write
1Execute

Examples:

chmod 755 file.sh
chmod 644 file.txt

Meaning:

  • 7 → rwx
  • 6 → rw-
  • 5 → r-x
  • 4 → 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 files
  • w → create/delete files
  • x → enter directory

📌 Execute permission is mandatory to access a directory.


11. Default Permissions & umask

  • umask sets 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 777 permissions
  • Use sudo carefully
  • Assign minimum required permissions
  • Use groups efficiently

14. File Permissions Summary Table

CommandPurpose
ls -lView permissions
chmodChange permissions
chownChange owner
umaskDefault 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.