Understanding File Permissions in Linux – A Beginner’s Guide
File permissions in Linux control who can read, write, or execute a file. Understanding these permissions is essential for system security, user management, and smooth application operation. In this guide, you’ll learn what Linux file permissions are, how they work, and how to change them with simple commands.
A fundamental security aspect of Linux is permissions, which regulate who can access, alter, or run files and folders. The owner, the group, and others (everyone else) are the three user classes to which they are assigned.
What Are File Permissions in Linux?
Every file and directory in Linux has permissions that define:
Who can read it
Who can modify it
Who can execute it
These permissions are divided into three categories:
Owner – the user who created the file
Group – users in the same group
Others – everyone else
Types of Permissions
Linux uses three main permission types:
Read (r) – view file content
Write (w) – modify or delete file
Execute (x) – run file as a program
Viewing File Permissions
Use the ls -l command:
ls -l file.txt
Example output:
-rw-r--r-- 1 user group 1200 Jan 18 file.txt
Breakdown:
-: file typerw-: owner permissionsr--: group permissionsr--: others permissions
Understanding Permission Format
Format:
rwxr-xr--
Meaning:
Owner: rwx (read, write, execute)
Group: r-x (read, execute)
Others: r-- (read only)
File vs Directory Permissions
For files:
r → read file
w → edit file
x → run file
For directories:
r → list files
w → add/delete files
x → enter directory
Changing Permissions with chmod
Using Symbolic Mode
chmod u+x file.sh # add execute to owner
chmod g-w file.txt # remove write from group
chmod o+r file.txt # add read to others
Using Numeric Mode
Numbers:
r = 4
w = 2
x = 1
Example:
chmod 755 script.sh
Meaning:
Owner: 7 → rwx
Group: 5 → r-x
Others: 5 → r-x
Changing Owner and Group
Use chown:
chown user file.txt
chown user:group file.txt
Special Permissions
SUID (Set User ID)
chmod u+s file
File runs with owner’s permissions.
SGID (Set Group ID)
chmod g+s dir
Files inside inherit group.
Sticky Bit
chmod +t /shared
Only file owner can delete files.
Common Permission Examples
| Command | Meaning |
|---|---|
| chmod 644 file.txt | Owner read/write, others read |
| chmod 700 private | Only owner access |
| chmod 777 file | Everyone full access (not recommended) |
Why File Permissions Matter
File permissions:
Protect sensitive data
Prevent unauthorized access
Control program execution
Improve system security
Wrong permissions can lead to data loss or hacking.
Conclusion
Understanding file permissions in Linux is essential for every user and administrator. Permissions define who can read, write, or execute files and directories. By learning commands like ls, chmod, and chown, you can manage security and access effectively in any Linux system.
Comments
Post a Comment