- Nikhil Bhaskar
- July 1, 2021
How to give file permissions on directories and regular files on Linux.
Linux is a multi-user operating system & can be accessed by many user.We can provide read ,write & execute permission to a file.There are 2 types of authorization levels.
- Ownership
- Permission
Ownership
Unix system have three types of owner:
- User: Who created the file & a user can create, delete, or modify the file.
- Group: All the users related to a group have same access permission for a file.
- Other: Any one who has access to the file other than user and group.Other have not a member of user or group.
Permission
Unix system have three types of permissions:
- Read (r) : we can only open and read the content of a file. But we can’t do any editing or modification in the file.
- Write (w) : we can only edit, remove or rename a file.
- Execute (x): we can run the file.
There are 2 type to use the command –
- Absolute mode
- Symbolic mode
Absolute(Numeric) Mode
Number | Permission Type | Symbol binary |
0 | No Permission | — 000 |
1 | Execute | –x 001 |
2 | Write | -w- 010 |
3 | Execute + Write | -wx 011 |
4 | Read | r– 100 |
5 | Read + Execute | r-x 101 |
6 | Read +Write | rw- 110 |
7 | Read + Write +Execute | rwx 111 |
Symbolic Mode
Operator | Description |
+ | Adds a permission to a file or directory |
– | Removes the permission |
= | Sets the permission |
The owners are represented as –
u : user/owner
g: group
o: other
a: All
Syntax:
chmod <groupName>+<permissionName> <fileName>
Example:
Give permission to execute is added to the user owner group.
chmod u+x file-name
Remove write & execute permissions from a user & group.
chmod u-w file-name
&
chmod g-x file-name
Give write permission for all the groups.
chmod a+w file-name
or
chmod +w file-name
Give read & write permission for others.
chmod o=rw file-name
Give permissions for all the three groups.
chmod u=rwx,g=rw,o=r file-name
Give Full permission to a folder
chmod 777 folder-name
change group-owner
chgrp group_name file-name