0 votes
in Linux by
Explain file permission in Linux.

1 Answer

0 votes
by

Explain file permission in Linux.

There are 3 kinds of permission in Linux:

Read: Allows a user to open and read the file

Write: Allows a user to open and modify the file

Execute: Allows a user to run the file.

You can change the permission of a file or a directory using the chmodcommand. There are two modes of using the chmod command:

Symbolic mode

Absolute mode

Symbolic mode

The general syntax to change permission using Symbolic mode is as follows:

$ chmod <target>(+/-/=)<permission> <filename>

where <permissions> can be r: read; w: write; x: execute.

<target> can be u : user; g: group; o: other; a: all

'+' is used for adding permission

'-' is used for removing permission

'=' is used for setting the permission

For example, if you want to set the permission such that the user can read, write, and execute it and members of your group can read and execute it, and others may only read it.

Then the command for this will be:

$ chmod u=rwx,g=rx,o=r filename

Absolute mode

The general syntax to change permission using Absolute mode is as follows:

$ chmod <permission> filename

The Absolute mode follows octal representation. The leftmost digit is for the user, the middle digit is for the user group and the rightmost digit is for all.

Below is the table that explains the meaning of the digits that can be used and their effect.

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

For example, if you want to set the permission such that the user can read, write, and execute it and members of your group can read and execute it, and others may only read it.

Then the command for this will be:

$ chmod 754 filename

Related questions

+1 vote
asked May 11, 2021 in Linux by rajeshsharma
0 votes
asked Nov 11, 2020 in Linux by sharadyadav1986
...