文件的权限管理

#1、创建g1组,要求创建一个属于redhat用户g1组的文件redhat.txt

[root@xxx ~]# groupadd g1

[root@xxx ~]# touch redhat.txt

[root@xxx ~]# ll redhat.txt

-rw-r--r--. 1 root root 0  4月 25 19:27 redhat.txt

[root@xxx ~]# chown redhat:g1 /root/redhat.txt

[root@xxx ~]# ll redhat.txt

-rw-r--r--. 1 redhat g1 0  4月 25 19:27 redhat.txt


#2、新建/sc目录,所属组为group组,root用户和group组用户可在该目录下创建文件,其他人无任何权限

[root@xxx ~]# groupadd group

[root@xxx ~]# mkdir /sc

[root@xxx ~]# chown :group /sc

[root@xxx ~]# ll /sc -d

drwxr-xr-x.   2 root group    6  4月 25 19:40 sc

[root@xxx ~]# chmod g+w /sc

[root@xxx ~]# chmod o-r /sc

[root@xxx ~]# chmod o-x /sc

[root@xxx ~]# ll /sc -d

drwxrwx---.   2 root group    6  4月 25 19:40 sc


#3、新建/cw目录为财务部存储目录,只能对财务部人员可以写入,并且财务部人员所建立的文件都自动属于mygroup组中

[root@xxx ~]# mkdir /cw

[root@xxx ~]# ll /cw -d

drwxr-xr-x. 2 root root 6  4月 26 20:22 /cw

[root@xxx ~]# groupadd mygroup

[root@xxx ~]# chown  :mygroup /cw

[root@xxx ~]# ll /cw -d

drwxr-xr-x. 2 root mygroup 6  4月 26 20:22 /cw

[root@xxx ~]# chmod g+w /cw

[root@xxx ~]# chmod g+s /cw

[root@xxx ~]# ll /cw -d

drwxrwsr-x. 2 root mygroup 6  4月 26 20:22 /cw

[root@xxx ~]# gpasswd -a wukong mygroup

正在将用户“wukong”加入到“mygroup”组中

[root@xxx ~]# su - wukong

[wukong@xxx ~]$ touch /cw/file1

[wukong@xxx ~]$ ll /cw

总用量 0

-rw-r--r--. 1 wukong mygroup 0  4月 26 20:41 file1


#4、设置helen用户对于/sc和/cw目录可读、可写、可执行

[root@xxx ~]# setfacl  -m  u:helen:rwx  /sc /cw

[root@xxx ~]# getfacl /sc  /cw

getfacl: Removing leading '/' from absolute path names

# file: sc

# owner: root

# group: group

user::rwx

user:helen:rwx

group::rwx

mask::rwx

other::---

# file: cw

# owner: root

# group: mygroup

# flags: -s-

user::rwx

user:helen:rwx

group::rwx

mask::rwx

other::r-x

#5、设置/test目录为公共存储目录,对所有用户可以读、写、执行,但用户只能删除属于自己的文件。

[root@xxx ~]# mkdir /test

[root@xxx ~]# ll /test -d

drwxr-xr-x. 2 root root 6  5月  2 10:19 /test

[root@xxx ~]# chmod g+w /test

[root@xxx ~]# chmod o+w /test

[root@xxx ~]# chmod o+t /test

[root@xxx ~]# ll /test -d

drwxrwxrwt. 2 root root 6  5月  2 10:19 /test

[root@xxx ~]# su - redhat

[redhat@xxx ~]$ touch /test/f1

[redhat@xxx ~]$ ll /test

总用量 0

-rw-r--r--. 1 redhat redhat 0  5月  2 10:23 f1

[redhat@xxx ~]$ exit

注销

[root@xxx ~]# su - wukong

[wukong@xxx ~]$ rm  -f /test/f1

rm: 无法删除 '/test/f1': 不允许的操作


#6、在/test/dir里创建的新文件自动属于temp组

[root@xxx ~]# mkdir /test/dir

[root@xxx ~]# ll /test/dir -d

drwxr-xr-x. 2 root   root   6  5月  2 10:32 dir

[root@xxx ~]# groupadd temp

[root@xxx ~]# chown :temp /test/dir

[root@xxx ~]# ll /test/dir -d

drwxr-xr-x. 2 root temp 6  5月  2 10:32 /test/dir

[root@xxx ~]# chmod g+s /test/dir

[root@xxx ~]# ll /test/dir -d

drwxr-sr-x. 2 root temp 6  5月  2 10:32 /test/dir

[root@xxx ~]# touch /test/dir/f2

[root@xxx ~]# ll /test/dir

总用量 0

-rw-r--r--. 1 root temp 0  5月  2 10:39 f2

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值