Linux: The concept of operating principles and permissions of shell commands

shell and kernel

In a narrow sense, Linux is an operating system. We call it kernel, which means the core. As the name suggests, the core is the most critical part. As an ordinary user, you cannot actually use the kernel. Instead, you will use a shell. This shell is the shell. Simply put, the shell is a layer of protection outside the kernel, a layer of shell, so why? Why can't I order the kernel? Why add a layer of shell outside? This requires a deeper understanding of the shell

The concept and principle of shell

From a technical point of view, the shell is actually a translator. It is responsible for inputting the instructions entered by the user to the core, allowing the core to process them, and then passing the results processed by the kernel to the user. It is a middleman.

In fact, there is a similar existence in Windows, this thing is called GUI: GUI is a graphical interface, it also plays a role in communicating with the user and the operating system, assuming that we want to access a folder now, our operation is usually to click on this file Folder, and the GUI is responsible for passing this command to the operating system, and the operating system will pass it back to the user after receiving the command, telling the user that he has successfully entered

And the shell is the same for Linux, if the user says I want

cat test.txt

Then the shell shell passes the command to the kernel, the kernel responds, and the shell shell passes it to the user

insert image description here
The above is an example of the role of the shell

Supplement:
In practical applications, the shell does not directly participate, but creates sub-processes one by one, allowing the sub-processes to execute commands, while the shell as the parent process continues to accept command lines to prevent unexpected situations from causing the shell Not working properly, more explanations will be given later in the process chapter

Linux permissions

Linux permissions are a major feature of Linux. Understanding Linux permissions is of great significance for future studies.

First of all, from the general direction, there are mainly two types of Linux users, root and ordinary users.
Super users : can do anything, as long as there are instructions to implement.
Ordinary users : relatively strong limitations, complete some basic operations

Two commands need to be added here:
Command 1: su username
Function: used to switch users

insert image description here
Command 2: sudo root
Function: Temporarily use the root account to execute commands, sudo can elevate the power in a short time, but the premise is that it is in the sudo list, otherwise the goal cannot be achieved:

insert image description here
Note that there is a detail here. You only need to use the free password, that is to say, you can achieve privilege escalation without using the root password. So why is this?
The reason is that this can prevent the password of the root account from being abused. In fact, it is also a kind of security. The root account can control whether a user can have root power or not.

file permissions

Linux permissions are often associated with files. For files, permissions are extremely important. Let’s understand permissions and files below.

First of all, for a document, there are often the following two types of attributes:
the first is the human attribute, that is, who wrote the document and who has the right to read it. Owner, Owner and Others
The second is the attribute of things, that is, who can access this file in what way. In Linux, the attributes of files are divided into three types, which are readable, writable, and executable. Corresponding to rwx respectively

file type

In our use in Windows, suppose we want to write a C language code, we will name it test.c, if we want to write a text file, we will write test.txt, because in Windows, a The type of file comes from its suffix, what the suffix looks like determines what kind of file it is, but this is not the case in Linux

In Linux, the type of file does not depend on the suffix, but depends on the first character in the directory, assuming here we create a file test

insert image description here

And the - at the beginning here actually represents what kind of file this is

In Linux there are the following file types:

d: folder-
: ordinary file
l: soft link (similar to Windows shortcut)
b: block device file (such as hard disk, CD-ROM, etc.)
p: pipeline file
c: character device file (such as screen and other serial devices)
s: set interface file

It should be noted that the meaning of the suffix in Linux is for people to see, but if it is a gcc compiler, it will also make a certain distinction between the suffix, but overall, Linux does not care much about the form of the file suffix

File permission management

Therefore, this time you can observe what its prefixes mean

insert image description here
Let's take a look at what these contents mean

insert image description here
It should be noted here that the second to tenth columns belong to the owner, the group to which they belong, and other people's permissions, and these permissions will not be displayed because they are not there, but will exist in the form of -, so There will be forms such as rw- — r–

Here are some additions to the knowledge shown above:

1. What is the connection between users and roles?
There is not much connection between users and roles. An ordinary user in a file is the user or the user group to which it belongs. The root user can also be neither the user nor the user group to which it belongs.

2. What is the group you belong to?
The group to which it belongs has its role in the process of developing the project. A group can have only one person or many people, and these people are all members of the project team

3. What is the use of the group you belong to?
To put it simply, the belonging group is used to create a person with partial permissions between the belonging user and other people. Suppose I have a project and I am in the process of perfecting it. At this time, other people want to see my project Work progress, I want to give him the permission to read, but I don't want to let others see it, so I can let him enter my group and give him the permission to read, so that both the permission to read and the permission to read are achieved. It can prevent others from seeing it. As the owner of the file, I can increase, modify and delete the power at any time. This is also one of the performances of the Linux system to improve work efficiency.

command to change permissions

Command: chmod
Function: Set the access permission of the file
Format: chmod [parameter] permission file name
Common options:
R -> Recursively modify the permission of the directory file
Note: Only the owner of the file and root can change the permission of the file

+: Add the authority indicated by the authority code to the scope of authority
-: Cancel the authority indicated by the authority code to the scope of authority
=: Grant the authority indicated by the authority code to the scope of authority
User symbols:
u: owner
g: owner in the same group
o: other users
a: all users

Practical application of permissions

After knowing the role of the authority, the following is the way to change the authority and the specific practical results

First, create a scene like this:

insert image description here
Then, at this time, test is the identity of other for the free folder. Now create a test file.
insert image description here
Based on what we learned above, we know that the test file has readable and writable rights for the owner, and for the group to which it belongs. There are readable and writable powers for others, and readable powers for others, so let’s add write permissions for other people to access the file

chmod o+w test

So under the test user, he can also use echo to modify the content in the test

echo "hello" >> test

insert image description here
At this time, I don't want the test user to see and write to my document anymore, so I can delete the permissions of the other user of the document

insert image description here
At this time, if the test user continues to access, it will prompt insufficient permissions

insert image description here

Guess you like

Origin blog.csdn.net/qq_73899585/article/details/131945695
Recommended