(1)创建g1组,要求创建一个属于redhat用户g1组的文件redhat.txt
#按照要求,先创建组g1及用户redhat。紧接着,创建文件,然后再修改文件的所属者和所属组
[root@localhost ~]# mkdir /redhat #创建目录
[root@localhost redhat]# touch redhat.txt #创建文件
[root@localhost redhat]# groupadd g1 #创建g1组
[root@localhost redhat]# useradd redhat #创建用户
[root@localhost redhat]# chown redhat:g1 redhat.txt #修改文件所属者和所属组
#修改前和修改后截图如下:
(2)新建/sc目录,所属组为group组,root用户和group组用户可在该目录下创建文件,其他人无任何权
限
#首先创建新目录、新组。修改文件的权限
[root@localhost ~]# mkdir /sc #创建目录
[root@localhost ~]# groupadd group #创建新组
[root@localhost sc]# chgrp group /sc #修改组
[root@localhost sc]# chmod g=rwx /sc #让组用户有编辑权限
#验证:让redhat属于group组,但xiaohei并不属于。
#效果:redhat能够创建文件,小黑只有读权限。
(3)新建/cw目录为财务部存储目录,只能对财务部人员可以写入,并且财务部人员所建立的文件都自动属于
mygroup组中
#创建目录,财务人员建立的文件都属于mygroup组,因此需要用到SGID权限。
[root@localhost ~]# mkdir /cw
[root@localhost cw]# useradd caiwu #添加财务人员
[root@localhost cw]# groupadd mygroup #创建组
[root@localhost cw]# chgrp mygroup /cw #修改所属组
[root@localhost cw]# chmod g=rwx /cw #给组成员添加权限
[root@localhost cw]# chmod g+s /cw #添加SGID权限
#caiwu人员创建的文件,属于mygroup组。其余用户没有写入的权利。
(4)设置 helen用户对于/sc和/cw目录可以读,写,执行
#指定helen用户对两个目录有相应的权限,使用ACL权限即可完成。
[root@localhost cw]# useradd helen
[root@localhost cw]# setfacl -m u:helen:rwx /sc
[root@localhost cw]# setfacl -m u:helen:rwx /cw
(5)设置/test目录为公共存储目录对所有用户可以读,写,执行,但用户只能删除属于自己的文件(t权
限)
#只能够删除属于自己的文件,使用SBIT权限即可。
[root@localhost ~]# mkdir /test
[root@localhost test]# chmod g=rwx /test
[root@localhost test]# chmod o=rwx /test
[root@localhost test]# chmod o+t /test #设置SBIT权限
#三个用户均在/test目录下,创建属于自己的文件。删除时,只能够删除属于自己的文件。
(6)在/test/dir里创建的新文件自动属于temp组
[root@localhost test]# mkdir dir
[root@localhost dir]# pwd
/test/dir
[root@localhost dir]# groupadd temp
[root@localhost dir]# chgrp temp /test/dir/
[root@localhost dir]# chmod g+s /test/dir/