Linux self-study journey-basic commands (basic permissions)

Linux self-study journey-basic commands (basic permissions)


Preface

1. In the previous section, we briefly introduced some commands that can be operated on directories and files, mainly about rm, cp, mv and other commands. If you haven’t read it, please click the link below to enter:
Directory and file operation commands

2. In this section, we mainly introduce some basic permission bits under Linux, mainly about what permissions are, why permissions are needed, and some basic permission bits under Linux.


Tip: The following is the content of this article

1. What are permissions?

1. When talking about authority, I don’t know if you have served as a class leader or something when you were in elementary school. Like when I was a child, I served as a learning committee once, everyone knows about the learning committee, that is, I usually accept homework and occasionally Help the teacher to change the homework together; because I am a study committee member, so after our exams, when everyone is worried about their grades and want to know, I actually laughed behind the back with their test papers. Yes, because I also want to help the teacher to change the test paper and count the results, everyone wants to know but can’t know the results in advance, but I can know the results in advance and change this situation, we can see it as a kind of authority . It is a kind of learning authority that can know in advance what everyone wants to know in the school. After I know the results, I have a good friend who wants to know the results in advance. I told him because he is a good friend of mine. We also call this kind of authority. I am the beneficiary of the main authority, and because he is a good friend of mine, he also has some authority incidentally, and then other people have nothing to do with me, so the authority is very few.

2. Therefore, we can regard authority as a kind of operation that is given by others and has more operations on one thing than others.

3. The same is true for permissions in our Linux, permissions are used to restrict a certain user or a restriction on file or directory operations for a certain type of person .


2. Why do I need permission?

1. Still the previous example, everyone imagine. If you don’t plan the permissions, if you can know the scores in advance and you can arbitrarily correct the scores and register the scores, what will happen? Is it just a mess, you can change the score, she can also change the score, and then you give yourself a high score , He gave a low score to another person who was uncomfortable with him. That is definitely not enough. At this time, it must be a relatively fair person who can have the authority to appear. In this way, part of the correction and registration of the grades are only operated by the relatively fair person (study committee), so that the order of our school can be guaranteed.

2. But at this time, in fact, it is impossible for all the papers to be corrected and registered to the study committee, because the study committee is also a student, and he has to take the exam himself, and the study committee is only learning better than the class. It's not too good, so it is not practical to give all the papers to the study committee. The study committee will also make mistakes. They may correct mistakes or secretly change their scores. So at this time we need the teacher, the teacher has all the authority, which test papers the teacher wants to modify for the study committee, the study committee can only modify those test papers, and other test paper study committees cannot operate normally, he can only have his own scope Part of the permissions within.

3. So it is the same in our Linux. The root user has all the permissions, and the ordinary users have some of the permissions. However, in general, we cannot log in with the root user account for any operation. This is the case in our company. Your boss uses You can only use ordinary user accounts for the root account. Needless to say, everyone should know why, because to ensure the security of the system, if everyone logs in with the root account, then everyone can do whatever they want to the system Is it? But at this time, although not everyone is root, but sometimes our ordinary users want to perform some necessary operations on the system or need some root privileges to operate, otherwise some work cannot be performed normally.

4. So why do we need permissions, because we have to divide what everyone can and cannot do !

4.1. The root user, he is the largest, and the system unconditionally believes in the operation of root, so in general Linux, root assigns permissions to others (root is omnipotent, even if your file owner is not root, root can also operate )

4.2. Group users, we should have said that there are owners and groups in Linux. For example, the owner of my file is root, and then my root has a group, which is also root (group name), then at this time our root The owner issued an order, and everyone in my root group can only read the file. So if the user Zhang San joins my root group at this time, he can only read files, and he can't do anything else.

4.3. Others, and in our Linux, if you are not the owner of this file or a user in the group to which you belong, then you are someone else; then at this time, the user root has ordered again, and people in the group to which this file belongs can No one else can do anything to read the file. So at this time Zhang San is in my root group, so he can read the file, and then Li Si comes. He is neither the owner of this file nor a user in the group he belongs to, so Li Si is someone else, then Li Si couldn't do any operation on the file, he couldn't even read it.


3. Introduction to basic permissions

1. Remember that we can use "ls -l" to see the contents of the directory in the long format display, as follows, the first row of information displayed in our long format is the permission bit of this file, and this permission bit determines one The user has some restrictions on the operation of this file.

[root@localhost ceshi]# ls -l
总用量 0
-rw-r--r--. 1 root root 0 1月  19 03:17 a.txt
[root@localhost ceshi]# 

Insert picture description here


2. Through the above example, we will take out the permission bits of the files separately
Insert picture description here


. 3. I said before that there are owners, groups and other people under Linux, then the permission bits are mainly for the division of these three types of people , So our authority position can be regarded as three parts:
Insert picture description here


4. As shown in the figure above, we can regard the middle "rw-", "r- -" and "r- -" as three parts separately (the first -And the last one. Leave it alone, it will take your time);

4.1. First is the first part "rw-". We call this first part the "u" permission bit for short, which is the permission bit of the owner of your file. The first part permission bit u determines that you create this All permissions of the creator of the file. (It is easy to understand, the first part can be regarded as you created this file, then what is your corresponding authority, as above, my owner's authority is rw-)

4.2. Then there is the second part "r–". This part is referred to as the "g" permission bit for short. The g permission bit represents the owner of your file, which group he belongs to, and the permissions that the people in this group have . (It's easy to understand. Didn't I create this file? The second part is which group my creator belongs to, and the permissions of my group members. As above, the permissions of people in my group are r–)

4.3. Then the third part is also "r–", and the third part is also referred to as the "o" permission bit. The o permission bit represents the permissions of other people except the owner and the people in the group you belong to. (It is easy to understand that I created the file, I have the corresponding permissions, and then the people in my group also have the corresponding permissions, then if there are other people who want to access my file, that person will also Does not belong to my group, then this o permission bit is the permission customized for those other people)


5. Then we will explain the permissions of one part separately

Insert picture description here
6. Let's talk about the permission bit of the first file owner. The permission bit of each part of ours is also divided into three small parts {

"R"=read permission (if your file owner permission bit has r in the first position, it means that you have read operation on this file, that is, you can open this file to see the contents)

"W"=write permission (if the owner permission bit of your file has w, it means you can write to this file, and you can change the contents of the file)

"X": Execution permission (if the owner permission bit of your file has x, it means that the file can have execution permission. What does it mean to execute the file is mentioned later, now it can be understood as the exe program under windows, right? Open to execute)

(If the owner permission bit of your file does not have one of the permissions listed above, then that place will become "-", as shown in the figure above, the owner of my file can only read and write to this file Operation, and no execution permission)

(The rwx in the permission bits of the group and other people have the same meaning)

}


to sum up

Because I have limited time to write a blog every day, I write here first, and then the first "-" and the last "." of the basic permission bits. We will continue in the next section, so we will talk about it in this section. { 1. What is permission: What can be restricted? 2. Why permission is needed: In order to ensure system security 3. Basic permission bits: file owner, group, other people [rwx] }



This is Jiehua, see you next time.

Guess you like

Origin blog.csdn.net/qq313088385/article/details/112857402
Recommended