Step by step
To implement this case, follow the steps below.
Step 1: create a new / nsddir1 / directory, and create a new file readme.txt in the directory
The command operation is as follows:
[root@localhost ~]# mkdir /nsddir1 [root@localhost ~]# ls -ld /nsddir1 / / / check whether the creation is successful drwxr-xr-x. 2 root root 4096 2 Month 2609:55 /nsddir1/ [root@localhost ~]# touch /nsddir1/readme.txt [root@localhost ~]# ls -l /nsddir1/readme.txt / / check whether the creation succeeds -rw-r--r--. 1 root root 0 2 Month 2609:56 /nsddir1/readme.txt [root@localhost ~]#
Step 2: enable users zhangsan to create / delete subdirectories under the directory / nsddir1 /
The command operation is as follows:
[root@localhost ~]# id zhangsan / / check whether the zhangsan user exists id: zhangsan: No such user [root@localhost ~]# useradd zhangsan / / create zhangsan user [root@localhost ~]# ls -ld /nsddir1 / / / view the permissions of nsddir1 directory drwxr-xr-x. 2 root root 4096 2 Month 2609:56 /nsddir1/
Analysis: first of all, we can see what permissions zhangsan has for this directory. It is obvious that zhangsan belongs to other people. The permissions correspond to rx. To enable it to create and delete subdirectories, it must have w permissions
[root@localhost ~]# su – zhangsan / / switch to zhangsan user test [zhangsan@localhost ~]$ mkdir /nsddir1/zhangdir //Test if you have permission to create mkdir: Unable to create directory"/nsddir1/zhangdir": insufficient privilege [zhangsan@localhost ~]$exit [root@localhost ~]# chmod o+w /nsddir1 / / / add w permission for others [root@localhost ~]# ls -ld /nsddir1 / / / check whether it is added successfully drwxr-xrwx. 2 root root 4096 2 Month 2609:56 /nsddir1/ [root@localhost ~]# su – zhangsan / / switch to zhangsan user test again [zhangsan@localhost ~]$ mkdir /nsddir1/zhangdir //Test if you have permission to create [zhangsan@localhost ~]$ ls /nsddir1/ //Check whether the creation is successful readme.txt zhangdir [zhangsan@localhost ~]$
Step 3: make users zhangsan unable to create / delete subdirectories under / nsddir1 / directory (this question examines the understanding of directory w permission)
[root@localhost ~]# chmod o-w /nsddir1 / / / remove w permission for others [root@localhost ~]# ls -ld /nsddir1 / / / check whether it succeeds drwxr-xr-x. 2 root root 4096 2 Month 2609:56 /nsddir1/ [root@localhost ~]# su – zhangsan / / switch to zhangsan user test [zhangsan@localhost ~]$ mkdir /nsddir1/zhangdir //Test if you have permission to create mkdir: Unable to create directory"/nsddir1/zhangdir": insufficient privilege
Step 4: enable the user zhangsan to modify the file / nsddir1/readme.txt, adjust the permissions of the directory / nsddir1 / so that no user can enter the directory, and test whether the user zhangsan can repair the contents of the file / nsddir1/readme.txt.
Analysis: first of all, we need to solve that zhangsan users can modify the readme.txt content
The command operation is as follows:
[root@localhost ~]# ls -ld /nsddir1/readme.txt / / view the permissions of the readme.txt file -rw-r--r--. 1 root root 0 2 Month 2609:56 /nsddir1/readme.txt //Analysis: first of all, we can see what permissions zhangsan has for this directory. It is obvious that the permissions of other people are r permissions. To realize how to let zhangsan modify its content, we need to add w permissions [root@localhost ~]# su – zhangsan / / switch to zhangsan user test [zhangsan@localhost ~]$ echo 123 > /nsddir1/readme.txt //Test whether you have permission to write -bash: /nsddir1/readme.txt: insufficient privilege [zhangsan@localhost ~]$ exit logout [root@localhost ~]# chmod o+w /nsddir1/readme.txt / / add w permission [root@localhost ~]# ls -l /nsddir1/readme.txt / / check to see if it is added successfully -rw-r--rw-. 1 root root 0 2 Month 2609:56 /nsddir1/readme.txt [root@localhost ~]# su – zhangsan / / switch to zhangsan user test [zhangsan@localhost ~]$ echo 123 > /nsddir1/readme.txt //Test whether you have permission to write [zhangsan@localhost ~]$ cat /nsddir1/readme.txt //View write success 123 //Analysis: zhangsan can modify the contents of readme.txt. Now setting the / nsddir1 permission means that no one can enter the directory, just remove the x execution permission of everyone. //The command operation is as follows: [root@localhost ~]# ls -ld /nsddir1/ drwxr-xr-x. 2 root root 4096 3 Month 3111:38 /nsddir1/ [root@localhost ~]# chmod a-x /nsddir1/ [root@localhost ~]# ls -ld /nsddir1/ drw-r--r--. 2 root root 4096 3 Month 3111:38 /nsddir1/ [root@localhost ~]# su - zhangsan [zhangsan@localhost ~]$ cd /nsddir1/ -bash: cd: /nsddir1/: insufficient privilege [zhangsan@localhost ~]$ echo 123 > /nsddir1/readme.txt //zhangsan user does not have permission to modify -bash: /nsddir1/readme.txt: insufficient privilege
Step 5: set the permissions of / nsddir1 / directory and all its contents to rwx-x - (the main inspection option of this topic is - R, which is still completed by chmod)
The command operation is as follows:
[root@localhost ~]# chmod -R 750 /nsddir1 / / - R is recursive modification [root@localhost ~]# ls -ld /nsddir1 / / / check whether the permissions of the directory are modified drwxr-x---. 3 root root 4096 2 Month 2616:00 /nsddir1/ [root@localhost ~]# ls -l /nsddir1 / / / check whether the permissions of subdirectories and sub files are modified //Total dosage 8 -rwxr-x---. 1 root root 4 2 Month 2616:14 readme.txt drwxr-x---. 2 zhangsan zhangsan 4096 2 Month 2616:00 zhangdir