RHCSA 第四天

1.复制/etc/shadow 文件到/media/test目录下,student1可以读写, student2不能做任何操作,其他用户可以读,设置teacher组为该文件的所属组。

[root@localhost ~]# cp /etc/shadow /media/test/.
[root@localhost ~]# setfacl -m u:student1:wr /media/test/shadow
[root@localhost ~]# setfacl -m u:student2:0 /media/test/shadow

2.当系统权限掩码默认为055时,默认创建文件和目录的权限是多少?

3.在/data/testdir里创建的新文件自动属于g1组,组g2的成员

  • 如:alice能对这些新文件有读写权限,组g3的成员

  • 如:tom只能对新文件有读权限,其它用户(不属于g1,g2,g3)不能访问这个文件夹(有问题)

[root@localhost ~]# groupadd g1
[root@localhost ~]# groupadd g2
[root@localhost ~]# groupadd g3
[root@localhost ~]# chgrp g+s /data/testdir/
[root@localhost ~]# chomd g+s /data/testdir/
[root@localhost ~]# cd /data/testdir/
[root@localhost testdir]# touch song
[root@localhost testdir]# ll
总用量 0
-rw-r--r--. 1 root root 0 9月  24 11:03 song
[root@localhost ~]# setfacl -m d:g:g2:rw /data/testdir/
[root@localhost ~]# touch /data/testdir/song2
[root@localhost ~]# getfacl /data/testdir/song2
getfacl: Removing leading '/' from absolute path names
# file: data/testdir/song2
# owner: root
# group: root
user::rw-
group::r-x   #effective:r--
group:g2:rw-
mask::rw-
other::r--
[root@localhost ~]# setfacl-m d:g:g3:r /data/testdir/
[root@localhost ~]# cd /data/testdir/
[root@localhost testdir]# touch song3
[root@localhost testdir]# getfacl song3
# file: song3
# owner: root
# group: root
user::rw-
group::r-x   #effective:r--
group:g2:rw-
mask::rw-
other::r--
[root@localhost ~]# chmod o-rwx /data/testdir/
[root@localhost ~]# getfacl /data/testdir/
getfacl: Removing leading '/' from absolute path names
# file: data/testdir/
# owner: root
# group: root
user::rwx
group::r-x
other::---
default:user::rwx
default:group::r-x
default:group:g2:rw-
default:mask::rwx
default:other::r-x
[root@localhost ~]# chmod o= -R /data
[root@localhost ~]# ll /data/testdir/
总用量 0
-rw-r-----. 1 root root 0 9月  24 11:03 song
-rw-rw----+ 1 root root 0 9月  24 11:07 song2
-rw-rw----+ 1 root root 0 9月  24 11:21 song3

综合练习:

1.在g1 g2 两个组分别有两个用户。

要求:在同一组中的成员可以互相看看文件不同组不能互相查看文件;

并且每个用户只能修改自己创建的文件和删除自己的文件。

[root@localhost ~]# useradd aa -g g1
[root@localhost ~]# useradd bb -g g1
[root@localhost ~]# useradd c -g g2
[root@localhost ~]# useradd d -g g2
[root@localhost ~]# chmod o+t+x /home/bb
[root@localhost ~]# ll -d /home/bb
drwx-----t. 3 bb g1 78 9月  24 12:24 /home/bb
[root@localhost ~]# chmod g+r+x /home/aa
[root@localhost ~]# ll -d /home/aa
drwxr-x---. 3 aa g1 78 9月  24 12:24 /home/aa
[root@localhost ~]# chmod g+r+x /home/c
[root@localhost ~]# chmod g+r+x /home/d
[root@localhost ~]# chmod o+t+x /home/c
[root@localhost ~]# chmod o+t+x /home/d
[root@localhost ~]# ll -d /home/c
drwxr-x--t. 3 c g2 78 9月  24 12:25 /home/c
[root@localhost ~]# ll -d /home/d
drwxr-x--t. 3 d g2 78 9月  24 12:25 /home/d
[root@localhost ~]# groupadd caiwu
[root@localhost ~]# useradd -G caiwu harry
[root@localhost ~]# chgrp caiwu /cw
[root@localhost ~]# chmod 2770 /cw
[root@localhost ~]# getfacl /cw
getfacl: Removing leading '/' from absolute path names
# file: cw
# owner: root
# group: caiwu
# flags: -s-
user::rwx
group::rwx
other::---

2.新建目录要求如下:

  • /pub目录为公共存储目录对所有用户可以读,写,执行,但用户只能删除属于自己的文件
  • /sc 目录为生产部存储目录只能对生产部人员可以写入,
    并且生产部人员所建立的文件都自动归属到shengchan组中
  • /cw 目录为财务部存储目录只能对财务部人员可以写入,
    并且财务部人员所建立的文件都自动归属到caiwu组中
  • admin用户能用touch工具在/sc目录中任意建立文件,但不能删除文件。
[root@localhost ~]# mkdir /pub
[root@localhost ~]# mkdir /sc
[root@localhost ~]# mkdir /cw
[root@localhost ~]# chmod 1777 /pub
[root@localhost ~]# ls -ld /pub
drwxrwxrwt. 2 root root 6 9月  24 12:35 /pub
[root@localhost ~]# groupadd shengchan
[root@localhost ~]# useradd -G shengchan tom
[root@localhost ~]# chgrp shengchan /sc
[root@localhost ~]# chmod 2770 /sc
[root@localhost ~]# ls -ld /sc
drwxrws---. 2 root shengchan 6 9月  24 12:36 /sc
[root@localhost ~]# getfacl /sc
getfacl: Removing leading '/' from absolute path names
# file: sc
# owner: root
# group: shengchan
# flags: -s-
user::rwx
group::rwx
other::---
[root@localhost ~]# groupadd caiwu
[root@localhost ~]# useradd -G caiwu harry
[root@localhost ~]# chgrp caiwu /cw
[root@localhost ~]# chmod 2770 /cw
[root@localhost ~]# getfacl /cw
getfacl: Removing leading '/' from absolute path names
# file: cw
# owner: root
# group: caiwu
# flags: -s-
user::rwx
group::rwx
other::---
[root@localhost ~]# setfacl -m u:admin:rwx /sc
[root@localhost ~]# setfacl -m u:admin:rwx /cw

3.1研发部开发人员David和Peter属于组A,行政部人员Jack和Mike属组B;

3.2建立目录“/project_a”,该目录里面的文件只能由研发部开发人员读取、增加、删除、修改以及执行,其他用户不能对该目录进行任何的访问操作;

3.3建立目录“/project_b”,该目录里面的文件只能由行政部人员读取、增加、删除、修改以及执行,其他用户不能对该目录进行任何的访问操作;

3.4建立目录“/project”,该目录里面的文件可由研发部、行政部人员读取、增加、删除、修改以及执行,其他部门用户只可以对该目录进行只读的访问操作

3.5通过vim文本编辑命令添加用户lucy,UID、GID为2222。

[root@localhost ~]# groupadd a;groupadd b;groupadd ab
[root@localhost ~]# useradd david
[root@localhost ~]# useradd peter
[root@localhost ~]# useradd mike
[root@localhost ~]# useradd jack
[root@localhost ~]# echo ‘1’ | passwd --stdin david
更改用户 david 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# echo ‘2’ | passwd --stdin peter
更改用户 peter 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# echo ‘3’ | passwd --stdin mike
更改用户 mike 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# echo ‘4’ | passwd --stdin jack
更改用户 jack 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# mkdir /project_a;mkdir /project_b;mkdir /project
[root@localhost ~]# chgrp a /project_a;chgrp b /project_b;chgrp ab /project
[root@localhost ~]# usermod -G a,ab david;usermod -G a,ab peter;usermod -G b,ab mike;usermod -G b,ab jack

猜你喜欢

转载自blog.csdn.net/weixin_45756724/article/details/108758277
今日推荐