Linux user and group authority management

Two user management

Every user must have a group, and a group has multiple users

Insert picture description here

As shown above: a.txt belongs to the user tom, the group of a.txt is group 1, because tom belongs to group 1, group 2 and group 3 are other groups for a.txt

1 Basic grammar

id wzh: query the uid, gid, group of the user wzh;

useradd wzh: The user who is wzh is added by the root user, and a wzh folder and a group named wzh are generated under /home. The user is logged in by default in the /home/wzh location and the wzh group

passwd wzh: modify the password of the user wzh, if the user name is not specified, it is specified for the currently logged in user

logout: log out of the current user, root is rarely used in work

su-user name: switch users directly after logging in, high-privilege switching low-privilege does not require password verification, anyway

userdel wzh: delete user wzh (will not affect the home directory, and the group where it belongs), userdel -r wzh: delete user wzh and delete /home/wzh at the same time, it is recommended to keep the home directory

whoami: displays the information of the user who logged in for the first time, even if the user switches users through su multiple times, the result is the same

groupadd dema: create a group employee, a user

groupdel dema: delete group employee

chown tom /home/test.txt: change the ownership of test.txt under home (created by root user) to tom (tom is in the student group)
chown -R tom /home/aaa: change aaa under home (created by root user) ) The ownership of all files in the directory is changed to tom (tom is in the student group)

chgrp employee /home/test.txt Change the file group, from student group to group employee
chgrp -R employee /home/aaa Change the group of all files in the /home/aaa directory, from student group to group employee

2 Practical case

1 Add a user named wzh with a home directory of /home/test useradd -d /home/test wzh;

2 Add a user wzh whose group is employee (existing): useradd -g employee wzh

3 Switch the wzh of the employee group to the manager group, usermod -g manager wzh

4 Query the detailed information of all files under /root including hidden files ls -al /root

5 ①Give the creator of the /home/test.txt file rwx, the group rw where it belongs, and other groups r permissions chmod u=rwx,g=rw,o=r /home/test.txt is equivalent to chmod 764 /home/test.txt② Remove the r permission from the owner of the /home/test.txt file, remove the w permission from the group, chmod ux,gw /home/test.txt

3 Detailed directory listing ls -ahl

/**
1、第一列表示的是文件的类型(0位)和权限(1-9位)

① 第0位用于标识该文件的类型
-:普通文件
d:代表目录
l:代表一个连接文件
c:字符设备,鼠标,硬件
b:块设备,硬盘

② 第1-3位用于确定文件所有者的权限,4-6位表示文件所在组的权限,7-9位表示文件其它组的权限
r:可读取该文件,作用于目录可以通过ls -l进行详细查看,用4来表示
w:可以对文件内容做任何操作,但不一定有删除该文件和重命名的权限,只有对文件上一级目录有w权限
才有该文件的删除和重命名权限,w作用与目录可以对该目录的文件新建,删除,重命名...,用2来表示
x:代表文件可执行,作用于目录代表该目录可以进入,用1表示
-:rwx出现任意位置代表没有相应的权限,如r--代表只读
数字表示权限:rwx代表7;r--代表4只读,-w-代表2只写

2、第二列数字如果是1表示一个普通文件,如果是一个文件夹那么这个数字的意义是该文件下的全部子
目录个数(每一层文件夹下都有两个特殊子目录".","..",分别表示当前层级的软连接和上一层级的软连接)
3、第三列代表文件的所属用户
4、第四列代表文件的所属组
5、第二列表示的是文件的大小,单位是字节
6、第六列是代表文件最后的修改时间
7、代表文件名
**/

[root@CentOSWzh-7 home]# ls -ahl
total 477M
drwxr-xr-x.  7 root    root     144 Jan 16 21:49 .
dr-xr-xr-x. 19 root    root    4.0K Dec 24 13:36 ..
-rw-r--r--.  1 root    root       0 Jan 16 21:48 cat.txt
-rwxr--r--.  1 root    root      18 Dec 24 13:49 mycal.sh
drwxr-xr-x.  2 root    root       6 Dec 24 17:46 newdisk
-rw-r--r--.  1 root    root    477M Jan 16 21:50 pc.tar.gz
-rw-r--r--.  1 root    root       0 Jan 16 21:48 pig.txt
drwx------. 15 rootwzh rootwzh 4.0K Jan 15 22:42 rootwzh
-rwxr--r--.  1 root    root      21 Dec 24 13:43 task.sh
drwx------.  5 xh      tt       123 Dec 24 12:08 xh
drwxr--r--.  6 xm      xm       135 Dec 24 11:13 xm
drwx------.  3 xq      tt        78 Dec 24 10:38 xq
You have new mail in /var/spool/mail/root

Guess you like

Origin blog.csdn.net/wwwwwww31311/article/details/112750935