The Linux filesystem gives us three types of permissions. Here is a simplified review:
Owner permissions − The owner’s permissions specifies what actions the owner of the file can perform on the file.
Group permissions − The group’s permissions specifies what actions a user, who is a member of the group that a file belongs to, can perform on the file.
Other (world) permissions − The permissions for others specifies what action all other users can perform on the file.
- User (or user owner)
- Group (or owner group)
- Other (everyone else)
File Access Modes –
Access modes defines the level of permissions a user/group or others have for a file or directory :
Read – Grants the capability to read, i.e., view the contents of the file.
Write – Grants the capability to modify, or remove the content of the file.
Execute – User with execute permissions can run a file as a program.
- Read
- Write
- eXecute
The permissions can be assigned/removed in form of numbers using +, – or = operators :-
Number | Permission Representation | Ref |
---|---|---|
0 | No permission | — |
1 | Execute permission | –x |
2 | Write permission | -w- |
3 | Execute and write permission: 1 (execute) + 2 (write) = 3 | -wx |
4 | Read permission | r– |
5 | Read and execute permission: 4 (read) + 1 (execute) = 5 | r-x |
6 | Read and write permission: 4 (read) + 2 (write) = 6 | rw- |
7 | All permissions: 4 (read) + 2 (write) + 1 (execute) = 7 | rwx |
Number | Chmod operator | Description |
---|---|---|
1 | + | Adds the permission |
2 | – | Removes the permission |
3 | = | Sets the permission |
# ls -l test
-rw-r--r-- 1 root root 18 Jun 29 21:56 test
# chmod +x test
# ls -l test
-rwxr-xr-x 1 root root 18 Jun 29 21:56 test
# chmod 775 test
# ls -l test
-rwxrwxr-x 1 root root 18 Jun 29 21:56 test
#
# ls -l test
-rwxrwxr-x 1 root root 18 Jun 29 21:56 test
# chown jay test
# ls -l test
-rwxrwxr-x 1 jay root 18 Jun 29 21:56 test
#
# chown jit:root test
# ls -l test
-rwxrwxr-x 1 jit root 18 Jun 29 21:56 test
#
# ls -l test
-rwxrwxr-x 1 jay root 18 Jun 29 21:56 test
# chgrp sys test
# ls -l test
-rwxrwxr-x 1 jay sys 18 Jun 29 21:56 test
#