Understanding of permissions issues - Linux

The Linux system can be learned well, and C++ can be described as like Yasuo riding a cat on his head, and Mark riding a Yao on his head, which is extremely happy.

1. Redirection

input redirection <direction, output redirection>, append redirection>>.

Second, the significance of learning Linux

What is Linux? He is an operating system.

It is a software for hardware and software resource management.

How does the operating system manage hardware? The operating system manages the hardware indirectly.

Linux is the foundation, and you can better accept learning other things. It is a platform. As long as you have learned about the operating system and computer network, you can see other things clearly.

A kernel distribution from a technical point of view of Linux. It is a digital number
Linux commercial distribution, such as ubuntu, red flag, etc.

3. The operating principle of the shell command

Generally, our users do not use the Linux kernel, and generally use the shell program to communicate with the kernel.
The shell is called the shell program.
The role of the shell is to bridge the connection between the user and the Linux kernel . It's the command line interpreter that translates commands entered by the user into something the kernel understands.

1. Translate the user's command to the core for processing
2. Translate the processing result of the core to the user at the same time.

Under Linux, the shell is the command line interpreter. Under Linux, it is called bash
. Under Windows, the shell is a graphical interface.

What is the significance of the existence of the shell ?
1. The significance of the existence of the shell shell is to reduce the cost of operating the OS.
2. The shell can protect the operating system.

The command line interpreter (shell) commonly used by our centos 7 is called the bash
shell, which is the general term for all interpreters. bash is one of the shells.

Fourth, Linux rights management

Linux is divided into two types of users, root users and ordinary users.

1. Classification of specific users in Linux

There is only one root user and ordinary users, and there can be a bunch of ordinary users.

Like windows, windows also has administrators and users.

The permissions of ordinary users are controlled.

Suppose now to determine who I am. To enter the command whoami.

Both root and ordinary users must set passwords. Never set the root password to be the same as that of a normal user. The password entered under the Linux system is not echoed . No echo means no black dots.

No echo is for security. Because the echo can get how many digits the password is.

su + username can switch to other normal users. If you are an ordinary user, you need to enter a password.

su 用户名

Five, the concept of permissions related to Linux files

First, use the ls -l command to display all the attributes of the file.

ls -l

insert image description here
First we look at the characters in the first column.
The first column represents the type of file . Under Linux, the file type is not distinguished by the file name suffix, which is different from windows.

But note that gcc is not a linux system, gcc is just a software on the linux system, so gcc recognizes the suffix.

file type

Under the Linux system.

- A bar: represents ordinary files (text, source code, executable programs, third-party dynamic and static libraries)
d: directory file
l: link file
p: pipeline file
b: block device file, disk file
c: character device file (that is terminal display)

file permissions

Authority = person + thing attribute.
What are permissions?
1. Constrain people
2. Have specific attributes when they need to correspond.

Who can and cannot access this file?
File permissions are divided into three categories r, x, w.
The corresponding file should have certain attributes. Such as r, w and execute x.

If you don't have rwx, even if the king of heaven comes, you can't read, write and execute.

In the Linux system, people are divided into three categories.
These three categories are specific roles, which can be root or ordinary users.

1. File owner The owner
is like you have a mobile phone. you are the owner

2. The group to which the file belongs, the group to which the grouper
belongs represents your friends or family members. Your family can also watch your phone.

Why is there a group in Linux?
Because if team programming is required, only the owner and other cannot allow others to participate. The appearance of the belonging group allows people in the same group to freely access the files in the group.

3. Other users of the file, other
This phone is not owned by other people. so everyone else is other

insert image description here

1. Three groups of three divide permissions respectively. The first group represents the owner's permission, the second group represents the group's permission, and the third group represents the other's permission.

The meaning of the position of each set of corresponding permissions is determined. rwx.

2. In the picture above, the first name of CaoShuai represents the owner of the file.

3.root represents the group to which the file belongs .

4.4096 This column represents the size of the file

What about the other file?
As long as it is not the owner and the third party of the group it belongs to, it is other.

File Permission Operations

File permissions are restricted to ordinary people. If it is root, although root is other relative to a certain file, it can be read, written and executed at will.

File permission operations involve two aspects.
1. Attributes of the revision file
2. Modifier

Usually, it is to modify an attribute corresponding to some people.

remove permissions

If you want to remove the read permission of the owner of test.c, it is the following command, u means owner- means minus, r means read

chmod u-r test.c

Remove the read r of the group to which it belongs

chmod g-r test.c

Remove other's reading r

chmod o-r test.c

add permissions

Add and subtract are opposite. understand at a glance

chmod u+rx test.c

Add r permission to the group to which it belongs

chmod g+r test.c

Add all permissions to other

chmod o+rwx test.c

Subtract permissions from multiple roles and separate them with commas.

chmod u-wx,g-w,o-rwx test.c

Octal file permission manipulation

For example, rwx can correspond to 111 in octal, which is 7 in decimal. For
example, 101 means 5, which means rx.

For example, set rwx permissions for everyone, which can be written as 777

The first 7 represents the owner, which is 111, the
second 7 represents the group it belongs to, which is 111, and the
third 7 represents other, 111

chomd 777 test.c

Change the owner and group of a file

For example, change the owner of the file test.c to root.
But you will find that it will not change.

Because in reality, if you want to give something to others, you need the consent of others.

chown root test.c//错误代码
sudo chown root test.c//正确代码

Sudo stands for elevated privileges, which can be forcibly stuffed to others after elevated privileges.

Although the owner of the file has changed to someone else, there are still restrictions on the directory permissions, so if the directory permissions are not given to others, others will not be able to access the file.

You can also switch to root to forcibly change the owner of the file.

Change the group to which a file belongs.

chgrp xjh test.c

Changing the owner and belonging group together is the middle price colon.

chgrp xjh:xjh test.c

Why doesn't sudo enter root's password?

Because in our system there is something called trust list.
If our sudo will report an error, it means that our user is not in the if trust list. We need to add trusted users to the trust list.

Must the creator and owner of the file be the same person?

The answer is not necessarily. Because we change the owner of the file.

6. Directory permissions

What permissions does the directory have?
We want to enter a directory, and the required permission is x, which is executable permission. This one is very special. need to remember

What would it look like if the directory didn't have r and w permissions?

If there is no r permission for the directory, ls cannot see the files in the directory. But it is allowed to write a file in the directory, but it is not allowed to view.

If there is no w permission for the directory, touch cannot create files and can only display files.

Conclusion: The r and w permissions of the directory represent the viewing and creation of files in the directory.

Everything under Linux is a file, and directories are also files.

file = content + attributes.
So the attribute of the directory is the permission, so what about the content?
The content represents the "properties" of some files (such as the file name)
;

Seven, the default permissions

The default permission of the directory is 775 The default permission of the
ordinary file is 664

Of course, different systems may have differences.
Why is the default permission like this?

1. The initial permissions of the default directory: start from 777
2. The default permissions of ordinary files: start from 666

Because there is a default permission mask in the system, called umask
, its value is 002.

permission mask

The so-called permission mask refers to: all permissions that appear in the permission mask should not appear in the final permission.

002 is the initial authority of the 000 000 010
directory: 111 111 111
, so the corresponding authority of the directory should be 111 111 101, which is 775

002 is the initial permission of 000 000 010
file: 110 110 110
and the default permission of the file is 110 110 100
which is 664

Guess you like

Origin blog.csdn.net/qq2466200050/article/details/128524492