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 21:40
下一篇 2016-08-04 21:40

相关推荐

  • Puppet 的使用与进阶

    Puppet 基于puppet 可实现自动化重复任务, 快速部署关键性应用以及在本地或云端完成主动管理变更和快速扩展架构规模.基于master/agent 模型. 基于RPC 的通信, 基于xml 进行数据交换 define : 使用puppet 语言来定义资源的状态模拟 : 根据资源关系图, puppet 可以模拟部署无损运行测试代码强制 : 对比客户端主…

    2016-12-04
  • N22第三周作业

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可 [root@localhost ~]# who |cut -d' ' -f1 |sort -u   root   xuc 2、取出…

    Linux干货 2016-08-29
  • rpm程序包管理器

    linux程序包管理器: 协作用户管理应用程序:安装、升级、查询、校验、卸载等 软件程序包生成过程:     源代码——》目标二进制格式–》组织成为一个或有限几个包文件     源代码:程序员写好的纯文本文档格式的代码     …

    Linux干货 2016-08-19
  • 马哥linux0803作业内容

    1. 创建sysadmins组 将用户user1,user2,user3加入sysadmins组中 将user3设置为sysadmins的管理员 用user3登录,将user2从组中移除 设置sysadmins的密码centos 设置user1 在创建新文件时,文件的所属组为sysadmins 删除user1…3 删除sysadmins 2、三种权限rwx对…

    Linux干货 2016-08-05
  • EXT4文件系统的初步使用

    文件系统的类型多种多样,我们接触得比较多的当属Windows系统上的FAT32和NTFS。 而EXT文件系统(Extended filesystem)则是linux上常见的文件系统类型。 目前最新的版本是ext4,常见于CentOS6之中。 1.查看当前系统中有没有挂载使用中的EXT4文件系统,可以使用mount命令: 2.如何创建一个EXT4的文件系统(f…

    系统运维 2016-02-14
  • shell脚本的一点补充

    脚本内容补充 数组 变量:存储单个元素的内存空间数组:存储多个元素的连续的内存空间,相当于多个变量的集合。 数组名和索引 索引:编号从0开始,属于数值索引注意:索引可支持使用自定义的格式,而不仅是数值格式,即为关联索引,bash4.0版本之后开始支持。bash的数组支持稀疏格式(索引不连续) 数组的使用 声明数组: declare -a ARRAY_NAME…

    Linux干货 2016-08-24