Linux (Unix) Permissions

Linux (Unix) Permissions

Today I will explain Linux permissions and how to modify them. Following pictures explain how its presented in cli

Another good example taken from google

First character represents the type of object in our case its file. In case of folders “d” is written instead of “-”
Next 9 characters allocated to permissions 3 characters for each group.

Thera 3 access types in Linux:

r – read
w – write
x – execute

We can check file permissions by issuing

ls -l

CHMOD command is used for modifying permissions. We can change permissions by two methods

1. Absolute Method
2. Symbolic Method

Following table depicts Absolute Method

From the above example

4+2+1=7
4+2+0=6
4+0+0=4

Therefore when we type:

chmod 764 myfile.txt

File permissions change as rwxrw-r– which results in the following permissions

User(Owner) – full permissions
Group – read, write permissions
Others – read permission

Other method is symbolic method. Following table symbolic method parameters.

In symbolic method we are adding or subtracting permissions by using the parameters in the above table

For example

chmod u+r MyFile.txt

Will add read permission to user(owner)

Some examples

Set the access type to read and execute for both the user and the group:

chmod ug+rx MyFile.txt

Set the access type to read and remove write access to the group and others:

chmod go+r-w MyFile.txt

Sets all users access type to read only:

chmod a=r MyFile3.txt

The difference between the last example and the others is that this syntax resets any access type bits that were set. In the other examples, the command only affects the access types that are called out in the command. If, in the first example, the write bit for the user was already set, it would remain set.

Comments are closed.