infoLinux

Linux File Permissions Introduction

The Linux or Unix system have three permission are below :

(a) user owner.

(b) group.

(c) others.

The Linux system have three types of permissions defined. All nine characters denotes the three types of permissions.

Read (r) : Permission of read (r) allows you to open and read the file content. You can not do any editing or modification in the file.

Write (w) : The permission of write (w) allows you to edit, remove or rename of a file content. You can change file content your own need.

Execute (x)Execute (x) permission can be execute the file. You can’t run or execute a program unless execute permission is set. In the Windows system, is no such permission available.

All the permissions are listed below:

permission

on a fileon a directory

r (read)

read file content (cat)read directory content (ls)

w (write)

change file content (vi)create file in directory (touch)

x (execute)

execute the fileenter the directory (cd)

Permission Set

Permission have ten characters (-rw-rw-r–) before the user owner. Now we can describe every ten characters below.

File permissions for (-rw-rw-r–)

position characters ownership
1 – denotes file type
2-4 rw- permission for user
5-7 rw- permission for group
8-10 r– permission for other

If you are user owner, your permission applies to you. This moment Other permissions are not relevant to you.

If you have the Group, So can the group permission applies to you. This time Other permissions are not relevant to you.

If you are the Other, then the other permission applies to you. That time User and group permissions are not relevant to you.

Permission Example

Now we can show some examples how permissions can be seen for a file or directory.

Here : different directories and files have different permissions.

The first letter (-) or represents the files and directories respectively.

From remaining nine letters,

The first time is triplet represents the permission for user owner.

Second time option is triplet represents the permission for group owner.

Third time option is triplet represents the permission for other .

Setting Permissions With chmod

Command of chmod is change the permission, accordingly to your need. Now we can show some examples to change the permissions for different groups.

To add permissions to a group.

Sample syntax of :

# chmod <groupName>+<permissionName> <fileName>

Like example of :

# chmod u+x file

See your terminal after run the command, permission to execute is added to the user owner group.

To remove permissions from a group

Sample syntax of :

# chmod <groupName>-<permissionName> <fileName>

Like example of :

# chmod g-x file  # chmod u-w file

See your terminal after run the command, permission to execute is removed from the group and permission to write is removed from the user owner.

To add permission to all the groups together

Sample syntax of :

# chmod a+<permissionName> <fileName>

Like example of :

# chmod a+w file

See your terminal after run the command, we have given permission to write for all the groups.

Here : Similarly, you can also remove the permission for all the groups.

To add permission to all the groups without typing a

Sample syntax of :

# chmod +<permissionName> <fileName>

Like example of :

# chmod +w file

See your terminal after run the command, this example is same as the earlier one only difference is that we haven’t typed a in this.

To set explicit permission

Sample syntax of :

# chmod <groupName>=<permissions> <fileName>

Like example of :

# chmod o=rw file

See your terminal after run the command, we have set explicit permission to read and write for others.

To set explicit permissions for different groups

Sample syntax of :

# chmod <groupName>=<permissions> <fileName>

Like example of :

# chmod u=rwx,g=rw,o=r file

See your terminal after run the command, If you practice more and more then you can gain expertness. Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *