What Are Permissions in Linux?
Linux is a multi-user system, meaning many users can share one machine. To keep things safe and organized, Linux assigns permissions to every file and folder.
These permissions determine:
Three Types of Users
Each file/folder has permissions for three categories of users:
-
Owner (u) – The person who created the file
-
Group (g) – A group the owner belongs to
-
Others (o) – Everyone else
Three Types of Permissions
| Symbol |
Permission |
Meaning |
r |
read |
Can view the file or list directory contents |
w |
write |
Can edit the file or add/delete files in a directory |
x |
execute |
Can run the file (if it's a script or program) |
Viewing Permissions
Use the ls -l command:
ls -l
Example output:
-rwxr-xr-- 1 user group 1234 Aug 6 file.sh
Breakdown:
So here:
Changing Permissions with chmod
The chmod command changes permissions.
Symbolic Mode (letters)
chmod u+x file.sh # Give execute permission to the owner
chmod g-w file.txt # Remove write from group
chmod o+r file.txt # Add read to others
Numeric Mode (numbers)
Each permission is a number:
Add the values to get the full permission.
| Permission |
Number |
rwx |
7 |
rw- |
6 |
r-- |
4 |
--x |
1 |
--- |
0 |
So chmod 755 file.sh means:
-
Owner: 7 = rwx
-
Group: 5 = r-x
-
Others: 5 = r-x
Changing Ownership with chown
You can change the owner and group of a file:
sudo chown user:group file.txt
Checking Effective Permissions
You can check your access to a file using:
ls -l file.txt
Or:
namei -l /path/to/file
Example Use Cases
| Task |
Required Permission |
| Read a text file |
r (read) |
| Edit a file |
w (write) |
| Run a script or program |
x (execute) |
| Enter a directory |
x (execute on the directory) |
| List files in a directory |
r (read on the directory) |