目录
2、将/www目录和name,https目录的所属者修改为web用户,并且web用户拥有所有的权限。
3、tom和jerry可以在name和https目录下新建和删除文件,其他用户没有任何权限。
1.新建一个组group1,将tom jerry加入该组, 然后对组进行权限设置
2. 验证----使用tom 、jerry 、redhat分别登录 ,并在目录下创建、删除文件 (结果应为在Redhat账户下因权限不够而无法创建文件)
4、复制/var/log/messages和/var/log/cron文件到/log目录,admin账号可以查看但不能修改该日志文件的内容。
5、复制/etc/ssh/sshd_config文件到/ssh目录,admin账号可以查看并修改该文件内容。
1、创建/www目录,在/www目录下新建name和https目录,在name和https目录下分别创建一个index.html文件,name下面的index.html文件中包含当前主机的主机名,https目录下的index.html文件中包含当前主机的ip地址。
[root@redhat ~]# mkdir -pv /www/name /www/https
mkdir: 已创建目录 '/www'
mkdir: 已创建目录 '/www/name'
mkdir: 已创建目录 '/www/https'
[root@redhat ~]# hostname > /www/name/index.html
[root@redhat ~]# cat /www/name/index.html
redhat
[root@redhat ~]# ip ad | grep ens160$ | tr -s " " | cut -d " " -f 3 | cut -d "/" -f1 > /www/https/index.html
[root@redhat ~]# cat /www/https/index.html
192.168.111.132

2、将/www目录和name,https目录的所属者修改为web用户,并且web用户拥有所有的权限。
[root@redhat ~]# useradd web
[root@redhat ~]# chown -R web /www/
[root@redhat ~]# ll -d /www/name/ /www/https/
drwxr-xr-x. 2 web root 24 3月 23 14:43 /www/https/
drwxr-xr-x. 2 web root 24 3月 23 14:39 /www/name/
[root@redhat ~]# setfacl -R -m u:web:rwx /www/
[root@redhat ~]# ll -d /www/name/ /www/https/
drwxrwxr-x+ 2 web root 24 3月 23 14:43 /www/https/
drwxrwxr-x+ 2 web root 24 3月 23 14:39 /www/name/
[root@redhat ~]# chown root:root /www/name/index.html /www/https/index.html
[root@redhat ~]# ll -d /www/name/index.html /www/https/index.html
-rw-rwxr--+ 1 root root 16 3月 23 14:43 /www/https/index.html
-rw-rwxr--+ 1 root root 7 3月 23 14:39 /www/name/index.html
[root@redhat ~]#
- web用户可对其进行增删改查 ---验证web用户已拥有所有权限
[root@redhat ~]# su -l web
[web@redhat ~]$ ll -d /www/name/ /www/https/
drwxrwxr-x+ 2 web root 24 3月 23 14:43 /www/https/
drwxrwxr-x+ 2 web root 24 3月 23 14:39 /www/name/
[web@redhat ~]$ cat /www/name/index.html
redhat
[web@redhat ~]$ echo '123' > /www/name/test
[web@redhat ~]$ cat /www/name/test
123
[web@redhat ~]$ echo 111 > /www/https/test
[web@redhat ~]$ cat /www/https/test
111
[web@redhat ~]$ rm -f /www/https/test
[web@redhat ~]$ rm -f /www/name/test
[web@redhat ~]$
3、tom和jerry可以在name和https目录下新建和删除文件,其他用户没有任何权限。
1.新建一个组group1,将tom jerry加入该组, 然后对组进行权限设置
[root@redhat ~]# useradd tom
[root@redhat ~]# useradd jerry
[root@redhat ~]# groupadd group1
[root@redhat ~]# gpasswd -M tom,jerry group1
[root@redhat ~]# id tom
用户id=1002(tom) 组id=1002(tom) 组=1002(tom),1004(group1)
[root@redhat ~]# id jerry
用户id=1003(jerry) 组id=1003(jerry) 组=1003(jerry),1004(group1)
[root@redhat ~]# chown -R :group1 /www/name/ /www/https/
[root@redhat ~]# chmod -R 770 /www/name/ /www/https/
[root@redhat ~]# ll -d /www/name/ /www/https/
drwxrwx---. 2 web group1 24 3月 23 15:37 /www/https/
drwxrwx---. 2 web group1 24 3月 23 15:37 /www/name/
[root@redhat ~]#
2. 验证----使用tom 、jerry 、redhat分别登录 ,并在目录下创建、删除文件 (结果应为在Redhat账户下因权限不够而无法创建文件)
tom账户:
[root@redhat ~]# su -l tom
[tom@redhat ~]$ touch /www/name/test
[tom@redhat ~]$ touch /www/https/test
[tom@redhat ~]$ tree /www/
/www/
├── https
│ ├── index.html
│ └── test
└── name
├── index.html
└── test
2 directories, 4 files
[tom@redhat ~]$ rm -f /www/name/test /www/https/test
[tom@redhat ~]$ tree /www/
/www/
├── https
│ └── index.html
└── name
└── index.html
jerry账户:
[root@redhat ~]# su -l jerry
[jerry@redhat ~]$ touch /www/name/ceshi /www/https/ceshi
[jerry@redhat ~]$ tree /www/
/www/
├── https
│ ├── ceshi
│ └── index.html
└── name
├── ceshi
└── index.html
2 directories, 4 files
[jerry@redhat ~]$ rm -f /www/name/ceshi /www/https/ceshi
[jerry@redhat ~]$ tree /www/
/www/
├── https
│ └── index.html
└── name
└── index.html
redhat账户:
[root@redhat ~]# su -l redhat
[redhat@redhat ~]$ touch /www/name/test
touch: 无法创建 '/www/name/test': 权限不够
[redhat@redhat ~]$ ll /www/name/
ls: 无法打开目录 '/www/name/': 权限不够
[redhat@redhat ~]$
4、复制/var/log/messages和/var/log/cron文件到/log目录,admin账号可以查看但不能修改该日志文件的内容。
[root@redhat ~]# mkdir /log
[root@redhat ~]# cp /var/log/messages /var/log/cron /log
[root@redhat ~]# useradd admin
[root@redhat ~]# setfacl -R -m u:admin:rx /log
[root@redhat ~]# getfacl /log/
getfacl: Removing leading '/' from absolute path names
# file: log/
# owner: root
# group: root
user::rwx
user:admin:r-x
group::r-x
mask::r-x
other::r-x
[root@redhat ~]#
[root@redhat ~]# su -l admin
[admin@redhat log]$ ll /log/
总用量 256
-rw-r-x---+ 1 root root 1184 3月 23 15:44 cron
-rw-r-x---+ 1 root root 254500 3月 23 15:44 messages
[admin@redhat log]$ cat cron

5、复制/etc/ssh/sshd_config文件到/ssh目录,admin账号可以查看并修改该文件内容。
[root@redhat ~]# mkdir /ssh
[root@redhat ~]# cp /etc/ssh/sshd_config /ssh/
[root@redhat ~]# setfacl -R -m u:admin:rwx /ssh/
[root@redhat ~]#

6、将复制过来的/ssh目录下的sshd_config文件中的非空行写入到/ssh/sshd文件中,将sshd_config文件中的非空行和非#号开头的行写入config文件中,并且admin可以查看sshd文件和config文件的内容。
[root@redhat ~]# grep ^$ -v /ssh/sshd_config > /ssh/sshd
[root@redhat ~]# grep ^$ -v /ssh/sshd_config | grep ^# -v > /ssh/config
[root@redhat ~]# setfacl -m u:admin:r /ssh/sshd /ssh/config
[root@redhat ~]# getfacl /ssh/sshd /ssh/config
getfacl: Removing leading '/' from absolute path names
# file: ssh/sshd
# owner: root
# group: root
user::rw-
user:admin:r--
group::r--
mask::r--
other::r--
# file: ssh/config
# owner: root
# group: root
user::rw-
user:admin:r--
group::r--
mask::r--
other::r--
[root@redhat ~]# su -l admin
[admin@redhat ~]$ ll /ssh/sshd /ssh/config
-rw-r--r--+ 1 root root 126 3月 23 16:09 /ssh/config
-rw-r--r--+ 1 root root 3643 3月 23 16:07 /ssh/sshd
[admin@redhat ~]$ 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.
# This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
# To modify the system-wide sshd configuration, create a *.conf file under
# /etc/ssh/sshd_config.d/ which will be automatically included below
...
[admin@redhat ~]$ cat /ssh/config
Include /etc/ssh/sshd_config.d/*.conf
AuthorizedKeysFile .ssh/authorized_keys
Subsystem sftp /usr/libexec/openssh/sftp-server
[admin@redhat ~]$