8.3-特殊权限(作业篇)

1. 在/data/testdir里创建的新文件自动属于g1组,组g2的成员如: alice能对这些新文件有读写权限,
组g3的成员如: tom只能对新文件有读权限,其它用户(不属于,g2,g3)不能访问这个文件夹

root@localhost ~]# mkdir -p /data/testdir
[root@localhost ~]# groupadd g1
[root@localhost ~]# groupadd g2
[root@localhost ~]# groupadd g3
[root@localhost ~]# ll /data/testdir/ -d
drwxr-xr-x. 2 root root 4096 7月  21 07:01 /data/testdir/
[root@localhost ~]# chmod g+s /data/testdir
[root@localhost ~]# ll /data/testdir/ -d
drwxr-sr-x. 2 root root 4096 7月  21 07:01 /data/testdir/
[root@localhost ~]# chown :g1 /data/testdir
[root@localhost ~]# ll /data/testdir/ -d
drwxr-sr-x. 2 root g1 4096 7月  21 07:01 /data/testdir/
[root@localhost ~]# useradd alice
[root@localhost ~]# gpasswd -a alice g2
正在将用户“alice”加入到“g2”组中
[root@localhost ~]# useradd tom
[root@localhost ~]# gpasswd -a tom g3
正在将用户“tom”加入到“g3”组中
[root@localhost ~]# setfacl -m d:g:g2:rw /data/testdir/
[root@localhost ~]# setfacl -m d:g:g3:r /data/testdir/
[root@localhost ~]# getfacl /data/testdir/
getfacl: Removing leading '/' from absolute path names
# file: data/testdir/
# owner: root
# group: g1
# flags: -s-
user::rwx
group::r-x
other::r-x
default:user::rwx
default:group::r-x
default:group:g2:rw-
default:group:g3:r--
default:mask::rwx
default:other::r-x
                    
[root@localhost ~]# chmod o= /data/testdir/
[root@localhost ~]# ll /data/testdir/ -d
drwxr-s---+ 2 root g1 4096 7月  21 07:01 /data/testdir/
[root@localhost ~]# setfacl -m g:g2:rwx /data/testdir/
[root@localhost ~]# setfacl -m g:g3:rwx /data/testdir/
创建新文件
touch /data/testdir/f2
g2组alice,对新文件f2可读写
[root@localhost ~]# su - alice
[alice@localhost ~]$ cat /data/testdir/f2
[alice@localhost ~]$ echo "aaa" > /data/testdir/f2
[alice@localhost ~]$ cat /data/testdir/f2
aaa
g3组:tom,对新文件只读
[root@localhost ~]# su - tom
[tom@localhost testdir]$ cat ./f2
[tom@localhost testdir]$ echo "a" >f2
-bash: f2: 权限不够
其他用户:user1,不能访问目录
[root@localhost ~]# su - user1
[user1@localhost testdir]$ cd /data/testdir/
-bash: cd: /data/testdir/: 权限不够

2.设置user1,使之新建文件权限为rw——-

[user1@localhost ~]$ umask 066
[user1@localhost ~]$ touch b
[user1@localhost ~]$ ll b
-rw-------. 1 user1 user1 0 7月  21 04:23 b

3.设置/testdir/f1的权限,使user1用户不可以读写执行,g1组可以读写

  [root@localhost /]# setfacl -m u:user1:---  /testdir/f1 
  [root@localhost /]# getfacl /testdir/f1
  getfacl: Removing leading '/' from absolute path names
  # file: testdir/f1
  # owner: root
  # group: root
  user::rw-
  user:user1:---
  group::r--
  mask::r--
  other::r--
  [root@localhost /]# groupadd g1
  [root@localhost /]# setfacl -m g:g1:rw /testdir/f1 
  [root@localhost /]# getfacl /testdir/f1
  getfacl: Removing leading '/' from absolute path names
  # file: testdir/f1
  # owner: root
  # group: root
  user::rw-
  user:user1:---
  group::r--
  group:g1:rw-
  mask::rw-
  other::r--

4./testdir/dir的权限,使新建文件自动具有acl权限:user1:rw,g1:—

[root@localhost /]# mkdir testdir/dir
[root@localhost /]# setfacl -m d:u:user1:rw testdir/dir
[root@localhost /]# setfacl -m d:g:g1:--- testdir/dir
[root@localhost /]# getfacl testdir/dir
# file: testdir/dir
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx
default:user:user1:rw-
default:group::r-x
default:group:g1:---
default:mask::rwx
default:other::r-x
[root@localhost ~]# chmod o+w  /testdir/dir/
[user1@localhost dir]$ touch /testdir/dir/f2
[user1@localhost dir]$ ll ./f2 
-rw-rw-r--+ 1 user1 user1 0 7月  21 05:42 ./f2

5.备份/testdir目录中所有文件的ACL,清除/testdir的所有ACL权限,并利用备份还原

[root@localhost ~]# getfacl /testdir/
getfacl: Removing leading '/' from absolute path names
# file: testdir/
# owner: root
# group: g1
# flags: -s-
user::rwx
group::r-x
group:g2:rwx
group:g3:rwx
mask::rwx
other::---
default:user::rwx
default:group::r-x
default:group:g2:rw-
default:group:g3:r--
default:mask::rwx
default:other::r-x

[root@localhost ~]# getfacl -R /testdir/ > /tmp/acl.txt

[root@localhost ~]# setfacl -b /testdir/
[root@localhost ~]# getfacl /testdir/
getfacl: Removing leading '/' from absolute path names
# file: testdir/
# owner: root
# group: g1
# flags: -s-
user::rwx
group::r-x
other::---

[root@localhost ~]# setfacl -R --set-file=/tmp/acl.txt /testdir/
[root@localhost ~]# getfacl /testdir/
getfacl: Removing leading '/' from absolute path names
# file: testdir/
# owner: root
# group: g1
# flags: -s-
user::rw-
group::r-x   #effective:r--
group:g2:rw-
group:g3:r--
mask::rw-
other::r--
default:user::rwx
default:group::r-x
default:group:g2:rw-
default:group:g3:r--
default:mask::rwx
default:other::r-x

6.当用户xiaoming对/testdir 目录无执行权限时,意味着无法做哪些操作?

[root@localhost ~]# ll /testdir/ -d
drwxr-xrw-. 2 root root 4096 7月  21 10:07 /testdir/
[xiaoming@localhost /]$ cd testdir/
-bash: cd: testdir/: 权限不够
[xiaoming@localhost /]$ ls /testdir/
ls: 无法访问/testdir/aaa: 权限不够
aaa
[xiaoming@localhost /]$ ls -l /testdir/
ls: 无法访问/testdir/aaa: 权限不够
总用量 0
-????????? ? ? ? ?            ? aaa
不能ls -l 此目录
不能cd进此目录

7.当用户xiaoqiang对/testdir 目录无读权限时,意味着无法做哪些操作?

[root@localhost /]# su - xiaoqiang
[xiaoqiang@localhost ~]$ cd /testdir/
[xiaoqiang@localhost testdir]$ ls
ls: 无法打开目录.: 权限不够
[xiaoqiang@localhost testdir]$ ll
ls: 无法打开目录.: 权限不够
[xiaoqiang@localhost testdir]$ rm -rf aaa
不能使用ls查看目录下文件

8.当用户wangcai 对/testdir 目录无写权限时,该目录下的只读文件file1是否可修改和删除?

[root@localhost testdir]# ll file1 
-rwxr-xr--. 1 root root 0 7月  21 10:30 file1
[root@localhost testdir]# su - wangcai
[wangcai@localhost ~]$ cd /testdir/
[wangcai@localhost testdir]$ ls
file1
[wangcai@localhost testdir]$ rm file1 
rm:是否删除有写保护的普通空文件 "file1"?y
rm: 无法删除"file1": 权限不够
[wangcai@localhost testdir]$ echo "a"> file1 
-bash: file1: 权限不够
不能修改,不能删除

9.复制/etc/fstab文件到/var/tmp下,设置文件所有者为wangcai读写权限,所属组为sysadmins组有读写权限,其他人无权限

[root@localhost ~]# cp /etc/fstab /var/tmp/
[root@localhost ~]# chown wangcai:sysadmins /var/tmp/fatsb
[root@localhost ~]# chmod 660 /var/tmp/fatab
[root@localhost ~]# ll /var/tmp/fstab
总用量 4
-rw-rw----. 1 root root 805 7月  21 10:33 fstab

10.误删除了用户wangcai的家目录,请重建并恢复该用户家目录及相应的权限属性

cp /etc/skel/ /home/wangcai
chown wangcai:wangcai /home/wangcai
chmod 600 /home/wangcai



原创文章,作者:M20-1--孔祥文,如若转载,请注明出处:http://www.178linux.com/28846

(1)
M20-1--孔祥文M20-1--孔祥文
上一篇 2016-08-04
下一篇 2016-08-04

相关推荐

  • hello! 我的博客第一站

    大家好!  这是我进博客的第一天,一个刚进来的新司机。在这里我就不秀我的车技了,只希望各位老司机开车不要太快,我晕车      —— 生命不息,奋斗不止

    Linux干货 2017-07-11
  • 马哥网络教育班第21期+第七周课程练习

    1、创建一个10G分区,并格式为ext4文件系统; (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; [root@localhost ~]# fdisk /dev/sd…

    Linux干货 2016-08-12
  • linux文件系统创建

    件系统管理 格式化:低级格式化(分区之前,划分磁道)         高级格式化:在分区之后进行,创建文件系统         元数据(也是放在块上(block)):inode  &nbsp…

    Linux干货 2016-08-29
  • Linux网络配置

    (1)、ifcfg家庭命令配置: ifconfig/route/netstat ifup/ifdown   (2)、ip命令配置: ip addr | route | link   (3)、修改配置文件 IP、MASK、GW、DNS相关配置文件:/etc/sysconfig/network-scripts/ifcfg-IFACE 路由相关…

    2018-01-30
  • 利用nginx实现基于传输层的四层负载均衡

    nginx利用ngx_stream_core_module实现四层的负载均衡服务。作为四层负载均衡nginx和lvs的区别在于: lvs工作于内核层,相对来说效率更高,性能更强; nginx工作于用户空间; lvs不会受到套接字数量的限制; nginx作为四层负载均衡也需要监听套接字来和客户端,后台服务器进行连接,会受到套接字数量限制,不过这个问题可以通过k…

    2017-07-03