Home >Operation and Maintenance >Linux Operation and Maintenance >Detailed introduction to Linux permissions

Detailed introduction to Linux permissions

王林
王林forward
2019-08-23 13:26:592018browse

Before understanding permissions, we need to know the user groups in Linux:

Every user in Linux belongs to a group, and every file in Linux has an owner, all groups, and other groups. We can understand these concepts using real-life examples. For example, if you have a book, then you are the owner of this book. You have the maximum permissions for this book. You can use, lend this book, and grant other permissions to this book. Other students in your class and you It can be regarded as one group, and students in other classes can be regarded as students in different groups. Now you have the maximum permissions for this book. You can also share this book with your classmates, so that you have the same permissions. The classmates in your class can also modify the permissions of this book. At this time, this book The book becomes a book shared by your class, and everyone in your class has the same permissions.

At the same time, there is also a root user in Linux. This user has the highest permissions. He has higher permissions than any other user, so he can modify the permissions of any other file.

File permissions:

We can use the command ls -l to view the detailed permissions of the file

Detailed introduction to Linux permissions

r : Indicates readable

w: Indicates writable

x: Indicates executable

You can also use numbers to indicate this. We will modify the file permission description.

For the rwx representation of the folder:

r means it can be read and the contents of the folder can be viewed and can be viewed by ls

w means it can be written and the content can be transferred to the folder For example, the file

x means it is executable and can be cd into the folder.

Modification of permissions:

In Linux, you can use chmod to modify the file. The permissions

rwx in Linux can also be represented by numbers

r=4

w=2

x=1

It is easy to understand when these are converted into binary: 4=0000 0100

2=0000 0010

1=0000 0001

So in normal times, file permissions are modified like this:

Detailed introduction to Linux permissions

7=4 2 1 and grant rwx permissions to owners, groups, and other users

Let’s take a look at the user permissions:

Detailed introduction to Linux permissions

As shown in the picture, I created a test.txt file using the hja account and the file permissions are owner rw

Members in the group rw

Others Group members do not have any permissions

Now we switch the hhh account:

Detailed introduction to Linux permissions

You can see that the permissions are insufficient, because hhh belongs to other groups, so there is no read permission. No delete permission

Detailed introduction to Linux permissions

Linux paste is (sticky bit):

To delete a file, you do not necessarily have to have write permission for the file, but you must You must have write permissions for the upper-level directory, which means that even if you do not have write permissions for this file, you can still delete this file if you have write permissions for the upper-level directory. The role of the sticky bit is to enable a directory to allow any user to write files but not allow other users to delete files.

Detailed introduction to Linux permissions

For more related questions, please visit the PHP Chinese website: linux video tutorial

The above is the detailed content of Detailed introduction to Linux permissions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete