0%

配置 /var/tmp/fstab 权限

将文件 /etc/fstab 复制到 /var/tmp/fstab。配置 /var/tmp/fstab 的权限以满足如下条件:

文件 /var/tmp/fstabroot 用户所有

文件 /var/tmp/fstab 属于组 root

文件 /var/tmp/fstab 应不能被任何人执行

用户 natasha 能够读取和写入 /var/tmp/fstab

用户 harry 无法写入或读取 /var/tmp/fstab

所有其他用户(当前或未来)能够读取 /var/tmp/fstab

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@node1 ~]# man -k acl
...
getfacl (1) - get file access control lists
...
setfacl (1) - set file access control lists
[root@node1 ~]# cp /etc/fstab /var/tmp/fstab
[root@node1 ~]# ls -l /var/tmp/fstab
-rw-r--r--. 1 root root 534 Feb 20 01:59 /var/tmp/fstab
[root@node1 ~]# cat /etc/group | grep root
root:x:0:
[root@node1 ~]# setfacl -m u:natasha:rw /var/tmp/fstab
[root@node1 ~]# setfacl -m u:harry:- /var/tmp/fstab
[root@node1 ~]# getfacl /var/tmp/fstab
getfacl: Removing leading '/' from absolute path names
# file: var/tmp/fstab
# owner: root
# group: root
user::rw-
user:natasha:rw-
user:harry:---
group::r--
mask::rw-
other::r--

[root@node1 ~]# ls -l /var/tmp/fstab
-rw-rw-r--+ 1 root root 534 Feb 20 01:59 /var/tmp/fstab

配置 autofs

配置 autofs,以按照如下所述自动挂载远程用户的主目录:

materials.example.com (172.25.254.254) NFS 导出 /rhome 到您的系统。此文件系统包含为用户 remoteuser1 预配置的主目录

remoteuser1 的主目录是 materials.example.com:/rhome/remoteuser1

remoteuser1 的主目录应自动挂载到本地 /rhome 下的 /rhome/remoteuser1

主目录必须可供其用户 写入

remoteuser1 的密码是 flectrag

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[root@node1 ~]# showmount -e materials.example.com
Export list for materials.example.com:
/rhome/remoteuser1 *
[root@node1 ~]# cat /etc/passwd | grep "remoteuser1"
remoteuser1:x:1002:1002::/rhome/remoteuser1:/bin/bash
[root@node1 ~]# yum list autofs
Installed Packages
autofs.x86_64 1:5.1.4-40.el8 @rhel-8.2-for-x86_64-baseos-rpms
[root@node1 ~]# systemctl is-active autofs.service
inactive
[root@node1 ~]# mount -t nfs materials.example.com:/rhome/remoteuser1 /mnt/
[root@node1 ~]# umount /mnt
[root@node1 ~]# vim /etc/auto.master.d/direct.autofs
# /etc/auto.master.d/direct.autofs
/- /etc/auto.direct
[root@node1 ~]# vim /etc/auto.direct
# /etc/auto.direct
/rhome/remoteuser1 -rw,sync materials.example.com:/rhome/remoteuser1
[root@node1 ~]# systemctl enable --now autofs.service
Created symlink /etc/systemd/system/multi-user.target.wants/autofs.service → /usr/lib/systemd/system/autofs.service.
[root@node1 ~]# ls -l /rhome/remoteuser1/
total 0
[root@node1 remoteuser1]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
...
materials.example.com:/rhome/remoteuser1 nfs4 50G 1.9G 49G 4% /rhome/remoteuser1
[root@node1 ~]# mount | grep "/rhome"
materials.example.com:/rhome/remoteuser1 on /rhome/remoteuser1 type nfs4 (rw,relatime,sync,vers=4.2,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=172.25.250.100,local_lock=none,addr=172.25.254.254)
1
2
3
4
5
[kiosk@foundation0 ~]$ ssh remoteuser1@172.25.250.100
remoteuser1@172.25.250.100's password:
[remoteuser1@node1 ~]$ pwd
/rhome/remoteuser1
[remoteuser1@node1 ~]$ touch tmpfile

配置 NTP

配置您的系统,使其成为 materials.example.com 的 NTP 客户端。(注:materials.example.comclassroom.example.com 的 DNS 别名)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[root@node1 ~]# systemctl list-units | grep NTP
chronyd.service loaded active running NTP client/server
[root@node1 ~]# man -k chrony
chrony.conf (5) - chronyd configuration file
chronyc (1) - command-line interface for chrony daemon
chronyd (8) - chrony daemon
[root@node1 ~]# systemctl is-active chronyd.service; systemctl is-enabled chronyd.service
active
enabled
[root@clear ~]# timedatectl
...
System clock synchronized: no
NTP service: active
[root@clear ~]# vim /etc/chrony.conf
# /etc/chrony.conf
server materials.example.com iburst
...
[root@clear ~]# systemctl restart chronyd.service
[root@clear ~]# timedatectl
...
System clock synchronized: yes
NTP service: active
[root@clear ~]# chronyc sources -v
210 Number of sources = 1

.-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* classroom.example.com 8 6 17 54 -33us[ -208us] +/- 750us

创建具有以下特征的协作目录 /home/managers

/home/managers 的组用权是 sysmgrs

目录应当可被 sysmgrs 的成员读取、写入和访问,但任何其他用户不具这些权限。(当然,root 用户有权访问系统上的所有文件和目录)

/home/managers 中创建的文件自动将组所有权设置到 sysmgrs

1
2
3
4
5
6
7
8
9
[root@node1 ~]# mkdir /home/managers
[root@node1 ~]# chown :sysmgrs /home/managers/
[root@node1 ~]# chmod 2770 /home/managers/
[root@node1 ~]# ls -ld /home/managers/
drwxrws---. 2 root sysmgrs 6 Feb 19 12:38 /home/managers/
[root@node1 ~]# touch /home/managers/tmpfile
[root@node1 ~]# ls -l /home/managers/
total 0
-rw-r--r--. 1 root sysmgrs 0 Feb 19 12:38 tmpfile

特殊权限对文件和目录的影响

特殊权限 对文件的影响 对目录的影响
u+s (suid) 以拥有文件的用户身份,而不是以运行文件的用户身份执行文件。 无影响。
g+s (sgid) 以拥有文件的组身份执行文件。 在目录中最新创建的文件将其组所有者设置为与目录的组所有者相匹配。
o+t (sticky) 无影响 对目录具有写入访问权限的用户仅可以删除其所拥有的文件,而无法删除或强制保存到其他用户所拥有的文件。

配置 cron 作业

配置 cron 作业,该作业 每隔 2 分钟 运行并执行以下命令:

logger "EX200 in progress",以用户 natasha 身份运行

配置 cron 作业

配置 cron 作业,以用户 harry 身份每天 14:23 分执行 /usr/bin/echo hello

1
2
3
4
5
6
7
8
9
10
11
[root@node1 ~]# systemctl is-active crond.service; systemctl is-enabled crond.service 
active
enabled
[root@node1 ~]# which logger
/usr/bin/logger
[root@node1 ~]# crontab -e -u natasha
no crontab for natasha - using an empty one
crontab: installing new crontab
[root@node1 ~]# crontab -l -u natasha
*/2 * * * * /usr/bin/logger "EX200 in progress"
[root@node1 ~]# grep EX200 /var/log/messages
1
2
3
4
5
[root@node1 ~]# crontab -e -u harry
no crontab for harry - using an empty one
crontab: installing new crontab
[root@node1 ~]# crontab -l -u harry
23 14 * * * /usr/bin/echo hello