Operating principles and permissions of Linux commands

insert image description here

1. Naming the line interpreter

insert image description here

insert image description here

Then the significance of the existence of the command line interpreter: 1. Interpret the command. 2. Protect the os, and directly intercept illegal requests.

2. Authority

1. User classification (su and exit)

insert image description here

1. Modify user

Enter root authority
insert image description here

Return to normal user

insert image description here

Become another user. If it is the root account, you do not need to enter a password. If you are an account of the same level, you need to enter a password.

insert image description here

Briefly elevate user privileges

insert image description here

After this command, enter your own password, so that you can temporarily enter the root authority. But in fact not all users can enter the root authority, your user must be in the trust white list.

2. Add white list

The following will use a little vim knowledge, you can check this blog portal

insert image description here

We need to use the root account to enter the sudoers file and add users to it.

insert image description here

After entering the small prompt, enter the following code to automatically standardize the line number

insert image description here

insert image description here
insert image description here

Pay attention to mandatory save

insert image description here

That's it

insert image description here

insert image description here

2. What is permission

1. Whether you are allowed to do a thing (related to the visitor)
2. File type and access permission (related to the attribute of the thing)

people

insert image description here

The people here refer to specific roles and authority identities. It is a mutual support relationship with our specific users, and different users can play different roles. Just like a person can be both a doctor and a father.

Attributes

insert image description here

insert image description here

insert image description here

3. Add and delete permissions (chmod)

Note that only the owner and root can use the addition and deletion permissions.

insert image description here

Add and delete permissions to the owner

insert image description here

insert image description here

Add and delete permissions to the group and others

insert image description here

Add and delete permissions for everyone

insert image description here

Because there are only two options of permission and no permission, if we regard permission as 1 and no permission as 0, then rwx can be written as 111, and converted to octal is 7, if we add rwx permission to everyone , then it is 777.

insert image description here

4. Change the owner of the permission (chown)

insert image description here

insert image description here

But when we operate directly, the operation is not allowed. This is because this kind of operation requires the consent of others, which is obviously difficult to operate here. So we can also force grant (requires privilege escalation to root).

You can also change the owner and group at once

insert image description here

Summarize
insert image description here

If I am both the file owner and the group I belong to, but as the file owner I only have read permission, and as the owner group I have both read and write permissions, can I write the file?
insert image description here

insert image description here

The answer is no. This is because only one authority can be selected for authentication, that is to say, because the owner authority has been authenticated first, then the authority of the group to which it belongs cannot be authenticated.

5. Three concepts

1. Permission mask (umask)

insert image description here

Why is the default permission for normal files rw-rw-r–(664)?

insert image description here

Why is the default permission of the created directory rwxrwxr-x (775)?

insert image description here

insert image description here

There is actually a permission mask umask here, which is actually octal, and the first 0 represents octal. Its function is that all permissions that appear in the umask will not appear in the final file permissions.

insert image description here

This looks a lot like subtraction, but in fact it cannot be viewed as subtraction. We can modify the permission mask here.

insert image description here

insert image description here

According to the deduction of subtraction, the permission of test3 here should be changed to 665, but in fact its permission is 666.

insert image description here

According to the definition of umask, in fact, the last digit of umaks here is 1, which means that the last digit of test3 is 0, but in fact the last digit of test3 is originally 0, so actually umaks does not work.

insert image description here

2. Directory permissions

The reading and writing of a document is easy to understand, so what does the reading and writing of a directory mean? First of all, step by step, why can we enter the directory?

insert image description here

Is it because we have read permissions, then remove this permission and see what happens.

insert image description here

We can find that we can still enter, but cannot view. This shows that the read permission is an operation that affects the view list. What about writing?

insert image description here

It is impossible to create files in the directory.

Summarize

insert image description here

3. Sticky bit

insert image description here

insert image description here

insert image description here

Then at this time, we can directly create a shared file in the root directory, and anyone can read and write in this file. But the problem is that anyone can write, which means that everyone can delete files arbitrarily, which is obviously unreasonable. So how do we avoid this problem? Can you remove the permission to write? The answer is no, if it is removed, then this shared file is meaningless, so we have to have a new concept to solve this problem. It's the sticky bit.

insert image description here

insert image description here

We can see that x here has changed to t, and t is actually an executable permission, but this permission is a bit special. This means you can create new files, but only delete or modify files you created yourself.

insert image description here

insert image description here

3. Summary of permissions

insert image description here

Guess you like

Origin blog.csdn.net/m0_73790767/article/details/130665555
Recommended