66.Linux group management and authority management

table of Contents

1. Introduction of Linux group

2. The owner of the file/directory

Three groups

(1) The creation of the group:

(2) View the group of the file/directory

(3) Modify the group where the file is located

(4) Other groups

Four, permissions

(1) The structure of viewing authority

(2) The role of rwx

(3) Modify permission command: chmod

(4) Modify the file owner instruction: chown

(5) Command to modify the group where the file/directory is located: chgrp


1. Introduction of Linux group

In Linux, each user must belong to a group and cannot be independent of the group.

In Linux, each file has the concept of owner, group, and other groups .

 

2. The owner of the file/directory

Owner: generally the creator of the file, whoever created the file is the owner of the file

#查看文件的所有者
ls -ahl

#修改文件的所有者
chown 用户名 文件名

View owner:

Change owner:

 

Three groups

(1) The creation of the group:

groupadd 组名

Examples:

Create a group and a user, and the files created by the user are also in the corresponding group:                      

(2) View the group of the file/directory

ls -ahl

(3) Modify the group where the file is located

chgrp 组名 文件名

(4) Other groups

Except for the owner of the file and the users in the group, other users of the system are other groups of the file.

 

Change other groups of users:

When adding a user, you can specify which group the user is added to. You can also change the user's group with root privileges.

#改变用户所在组
usermod -g 组名 用户名
usermod -d 目录名 用户名 改变该用户登录的初始目录

 

Four, permissions

(1) The structure of viewing authority

We enter ll and see the following content:

There are 10 characters in the place I framed, corresponding to 0-9 digits. What do these 10 characters correspond to?

*1) The 0th bit determines the type of file

l is a link, equivalent to a shortcut in Windows

d is a directory, which is equivalent to a folder in Windows

c is a character device, such as a mouse, keyboard

b is a block device, such as a hard disk

-Indicates that it is a normal file

*2) The first 1-3 determine the owner's authority

*3) The 4-6 digits determine the authority of the group belonging to

*4) Numbers 7-9 determine the permissions corresponding to other users

 

(2) The role of rwx

The role of rwx for files:

*1) r: can read and view

*2) w: Can be modified, but cannot be deleted. To delete a file, you need to have the right to write to the directory where the file is located

*3) x: Can be executed

 

The role of rwx for directories:

*1) r: can be read, ls view the contents of the directory

*2) w: can be modified, you can create + delete + rename the directory in the directory

*3) x: can be executed, that is, you can enter the directory

 

Among them, rwx can also be represented by numbers:

r=4,w=2,x=1, if there are three permissions, it is 7

 

Example:

Let's analyze what the results mean:

The first column indicates permissions . If the second column is a file , it indicates the number of hard links ; if it is a directory, it indicates the number of subdirectories.

The third column indicates the user , the fourth column is the group , and the fifth column is the file size . If it is a folder, it will display 4096 bytes.

The sixth column indicates the last modification time , and the seventh column indicates the file name .

 

(3) Modify permission command: chmod

The first way: through "+", "-", "=" to change permissions

u: owner, g: all groups, o: others, a: everyone

#指定权限
chmod u=rwx,g=rx,o=x 文件/目录名

#变更权限
chmod o+w 文件/目录名

chmod a-x 文件/目录名

Examples:

The second way: change permissions through numbers

r=4,w=2,x=1,r+w+x=7

chmod 751 文件/目录名

 

(4) Modify the file owner instruction: chown

chown newowner 文件/目录 改变所有者
chown newowner:newgroup 文件/目录 改变所有者和所在组

-R:如果是目录,则使其下所有子文件或目录递归生效

Example:

 

(5) Command to modify the group where the file/directory is located: chgrp

chgrp [-R] newgroup 文件/目录 改变所有组

-R:如果是目录,则使其下所有子文件或目录递归生效

 

Guess you like

Origin blog.csdn.net/qq_40594696/article/details/113900004