Posted in: Linux

Permissions in Linux

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 :-

NumberPermission RepresentationRef
0No permission
1Execute permission–x
2Write permission-w-
3Execute and write permission: 1 (execute) + 2 (write) = 3-wx
4Read permissionr–
5Read and execute permission: 4 (read) + 1 (execute) = 5r-x
6Read and write permission: 4 (read) + 2 (write) = 6rw-
7All permissions: 4 (read) + 2 (write) + 1 (execute) = 7rwx
NumberChmod operatorDescription
1+Adds the permission
2Removes the permission
3=Sets the permission
chmod :-
 
chmod is used to manipulate the file/directory’s permissions.
 
Example :
Original permission –
# ls -l test
-rw-r--r-- 1 root root 18 Jun 29 21:56 test
 
Added execute permission for the file’s “owner”, “group” as well as “others”
# chmod +x test

# ls -l test
-rwxr-xr-x 1 root root 18 Jun 29 21:56 test
 
Added write and execute permission to the “owner” and “group”(hence 7(4+2+1),7(4+2+1)) ; read and execute permission to “others” (5 (4+1)) hence 
# chmod 775 test

# ls -l test
-rwxrwxr-x 1 root root 18 Jun 29 21:56 test
#
 

chown :-
chown is used to change the ownership of a file or directory.
 
# 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
#
 
owner and group both can be changed with a single chown command –
# chown jit:root test

# ls -l test
-rwxrwxr-x 1 jit root 18 Jun 29 21:56 test
#
 

chgrp :-
 
This is used to change the group for the file or directory.
 
# 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

#

Back to Top