Every file and directory in Linux has permissions assigned to three categories:
- User (Owner): A user is the owner of the file. By default, the person who created a file becomes its owner.
- Group: A user- group can contain multiple users. All users belonging to a group will have the same Linux group permissions access to the file.
- Others: Any other user who has access to a file.
Each category has three types of permissions:
r(Read) → Can view the file contentsw(Write) → Can modify the filex(Execute) → Can run the file (if it's a script or program)
Linux uses a 3-digit numeric system to represent permissions. The digits come from adding these values:
- Read (r) = 4
- Write (w) = 2
- Execute (x) = 1
Each digit represents the sum of allowed permissions for User, Group, and Others.
| Permission | Numeric Code | Explanation |
|---|---|---|
--- |
0 | No permissions (0) |
--x |
1 | Execute only (1) |
-w- |
2 | Write only (2) |
-wx |
3 | Write + Execute (2+1) |
r-- |
4 | Read only (4) |
r-x |
5 | Read + Execute (4+1) |
rw- |
6 | Read + Write (4+2) |
rwx |
7 | Read + Write + Execute (4+2+1) |
-rw-r--r-- 1 foyez staff 1156 Feb 25 14:06 Makefile
-→ This is a file (if it were a directory, it would bed)rw-(User) → Read & Write (4+2 = 6)r--(Group) → Read only (4)r--(Others) → Read only (4)
Use the chmod command:
chmod 755 file.shThis sets:
- User:
rwx(7) - Group:
r-x(5) - Others:
r-x(5)