五一作业 (rhcsa)

本文详细介绍了如何在Linux系统中创建不同权限的文件和目录,包括使用groupadd、chown、chmod命令设置用户、组和文件权限,以及如何创建公共存储目录和自定义组权限。
摘要由CSDN通过智能技术生成

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

[root@localhost ~]# groupadd g1

[root@localhost ~]# touch /home/redhat/redhat.txt            

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

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

[root@localhost ~]# mkdir /sc

[root@localhost ~]# groupadd group

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

[root@localhost ~]# chmod 770 /sc

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

[root@localhost ~]# groupadd caiwu

[root@localhost ~]# groupadd mygroup

[root@localhost ~]# mkdir /cw

[root@localhost ~]# chown root:caiwu /cw

[root@localhost ~]# chmod 770 /cw

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

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

drwxrwx---. 2 root g1 6  5月  5 13:02 /sc

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

[root@localhost ~]# ll /cw

总用量 0

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

drwxrws---. 2 root caiwu 6  5月  5 13:05 /cw

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

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

drwxrws---. 2 root mygroup 6  5月  5 13:05 /cw

[root@localhost ~]# chmod 770 /cw

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

drwxrws---. 2 root mygroup 6  5月  5 13:05 /cw

[root@localhost ~]# gpasswd -M redhat mygroup

[root@localhost ~]# su redhat

[redhat@localhost root]$ touch /cw/new1

[root@localhost ~]# ll /cw

总用量 0

-rw-r--r--. 1 redhat mygroup 0  5月  5 14:08 new1

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

[root@localhost ~]# useradd hele

-rw-r--r--. 1 redhat mygroup 0  5月  5 14:08 new1

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

drwxrws---. 2 root mygroup 18  5月  5 14:08 /cw

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

drwxrwx---. 2 root group 6  5月  5 13:02 /sc

[root@localhost ~]# setfacl -m u:hele:rwx /sc

[root@localhost ~]# setfacl -m u:hele:rwx /cw

[root@localhost ~]# su hele

[hele@localhost root]$ ll /cw

总用量 0

-rw-r--r--. 1 redhat mygroup 0  5月  5 14:08 new1

[hele@localhost root]$ ll /sc

总用量 0

[hele@localhost root]$ touch /sc/fail1

[hele@localhost root]$ ll /sc

总用量 0

-rw-r--r--. 1 hele hele 0  5月  5 14:13 fail1

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

[root@localhost ~]# mkdir /test

[root@localhost ~]# chown 777 /test/

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

drwxr-xr-x. 2 777 root 6  5月  5 14:15 /test/

[root@localhost ~]# chmod 777 /test

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

drwxrwxrwx. 2 777 root 6  5月  5 14:15 /test/

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

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

drwxrwxrwt. 2 777 root 19  5月  5 14:17 /test/

[root@localhost ~]# ll /test/

总用量 0

-rw-r--r--. 1 hele hele 0  5月  5 14:17 file1

[root@localhost ~]# ll /test/

总用量 0

-rw-r--r--. 1 hele   hele   0  5月  5 14:17 file1

-rw-r--r--. 1 redhat redhat 0  5月  5 14:18 file2

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

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

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

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

[root@localhost ~]# groupadd temp

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

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

drwxr-srwx. 2 root temp 6  5月  5 14:20 /test/dir/

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

总用量 0

-rw-r--r--. 1 redhat temp 0  5月  5 14:22 555

  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值