Linux权限设置

(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/

在这里插入图片描述

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值