1、创建/www目录,在/www目录下新建name和https目录,在name和https目录下分别创建一个index.html文件,name下面的index.html文件中包含当前主机的主机名,https目录下的index.html文件中包含当前主机的ip地址。
[root@first ~]# mkdir /www
[root@first ~]# mkdir /www/{name,https}
[root@first ~]# touch /www/{name,https}/index.html
[root@first ~]# hostname
first
[root@first ~]# echo first </www/name/index.html
first
[root@first ~]# echo 192.168.199.128 </www/https/index.html
192.168.199.128
[root@first ~]# tree /www
/www
├── https
│ └── index.html
└── name
└── index.html
2 directories, 2 files
2、将/www目录和name,https目录的所属者修改为web用户,并且web用户拥有所有的权限。
[root@first ~]# useradd wed
[root@first ~]# passwd wed
更改用户 wed 的密码 。
新的密码:
无效的密码: 密码少于 8 个字符
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。
[root@first ~]# ll /www
总用量 0
drwxr-xr-x. 2 root root 24 3月 23 14:42 https
drwxr-xr-x. 2 root root 24 3月 23 14:42 name
[root@first ~]# chown -R wed:wed /www/{name,https}
[root@first ~]# ll /www
总用量 0
drwxr-xr-x. 2 wed wed 24 3月 23 14:42 https
drwxr-xr-x. 2 wed wed 24 3月 23 14:42 name
3、tom和jerry可以在name和https目录下新建和删除文件,其他用户没有任何权限。
[root@first ~]# useradd tom
[root@first ~]# passwd tom
更改用户 tom 的密码 。
新的密码:
无效的密码: 密码少于 8 个字符
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。
[root@first ~]# useradd jerry
[root@first ~]# passwd jerry
更改用户 jerry 的密码 。
新的密码:
无效的密码: 密码少于 8 个字符
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。
[root@first ~]# chmod 674 /www
[root@first ~]# chmod 674 /www/{name,https}
[root@first ~]# ll /www
总用量 0
drw-rwxr--. 2 wed group1 24 3月 23 14:42 https
drw-rwxr--. 2 wed group1 24 3月 23 15:22 name
[root@xiaokeai ~]# usermod -aG group1 tom
[root@xiaokeai ~]# usermod -aG group1 jerry
[root@first ~]# su tom
[tom@first root]$ touch /www/name/1.txt
[tom@first root]$ rm -rf /www/name/1.txt
[tom@first root]$ su admin
密码:
[admin@first root]$ touch /www/name/1.txt
touch: 无法创建 '/www/name/1.txt': 权限不够
4、复制/var/log/messages和/var/log/cron文件到/log目录,admin账号可以查看但不能修改该日志文件的内容。
[root@first ~]# cp /var/log/cron /log
[root@first ~]# cp /var/log/messages /log
cp:是否覆盖'/log'? n
[root@first ~]# ll /log
-rw-------. 1 root root 227640 3月 23 15:27 /log
[root@first ~]# useradd admin
[root@first ~]# passwd admin
更改用户 admin 的密码 。
新的密码:
无效的密码: 密码少于 8 个字符
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。
[root@first ~]# chown admin:admin /var/log/{messages,cron}
[root@first ~]# chown 400 /var/log/{messages,cron}
[root@first ~]# su admin
[admin@first root]$ cat /var/log/messages
Mar 23 14:35:34 localhost kernel: The list of certified hardware and cloud instances for Red Hat Enterprise Linux 9 can be viewed at the Red Hat Ecosystem Catalog, https://catalog.redhat.com.
[admin@first root]$ ll /var/log/messages
-rw-r--r--. 1 400 admin 231949 3月 23 16:51 /var/log/messages
[admin@first root]$ echo 123 >>/var/log/cron
bash: /var/log/cron: 权限不够
5、复制/etc/ssh/sshd_config文件到/ssh目录,admin账号可以查看并修改该文件内容。
[root@first ~]# mkdir -p /ssh
[root@first ~]# cp /etc/ssh/sshd_config /ssh/
[root@first ~]# cd /ssh
[root@first ssh]# ls
sshd_config
[root@first ssh]# cd
[root@first ~]# setfacl -m u:admin:rwx /ssh/sshd_config
[root@first ~]# su admin
[admin@first root]$ cat /ssh/sshd_config
# $OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
[admin@first root]$ echo 123 >> /ssh/sshd_config
6、将复制过来的/ssh目录下的sshd_config文件中的非空行写入到/ssh/sshd文件中,将sshd_config文件中的非空行和非#号开头的行写入config文件中,并且admin可以查看sshd文件和config文件的内容。
[root@first ~]# grep -v "^$" /ssh/sshd_config > /ssh/sshd
[root@first ~]# grep -vE "^$|^#" /ssh/sshd_config > /ssh/config
[root@first ~]# setfacl -m u:admin:r /ssh/{sshd,config}
[root@first ~]# su admin
[admin@first root]$ cat /ssh/sshd
# $OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
[admin@first root]$ cat /ssh/config
Include /etc/ssh/sshd_config.d/*.conf
AuthorizedKeysFile .ssh/authorized_keys
Subsystem sftp /usr/libexec/openssh/sftp-server
123