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

相关推荐

  • 马哥Linux学习之查询篇(命令查询和文件查询)

        Linux运维工作一般都使用命令完成,在如此多的各种命令中,要想全部记住显然是不太可能也是不必要的,另外,文件的查找在日常操作中也是必不可少的。下面我就总结一下Linux中如何查找命令以及文件。     命令的运行文件路径查询。这个查找的方法是同样是使用命令,这个命令叫w…

    Linux干货 2015-04-13
  • Web缓存核心技术点需知

    Edit Web缓存核心技术点需知 5.1 HTTP首部控制 5.2 基于新鲜度检测机制: 2.1 特征1:时间局部性 2.2 特征2:空间局部性 2.3 缓存的优点 2.4 哪类数据应该被缓存 2.5 哪类数据可缓存但不应该被缓存 2.6 缓存命中率决定缓存有效性 2.7 缓存数据生命周期 2.8 缓存处理步骤 2.9 缓存和普通数据读取的区别 1. 完整…

    Linux干货 2016-11-14
  • grep&正则表达式

    grep&正则表达式 grep(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。 语法 grep [选项]… PATTERN [FILE]… 选项 -a 不要忽略…

    Linux干货 2018-03-23
  • 马哥教育首届IT技术博客大赛–复审阶段

    马哥教育首届IT博客大赛大众评审开始了 2016年马哥教育首届IT博客技术大赛,评委初审已结束,正式进入大众评审阶段。。。。 此次博客大赛,虽然因为准备时间比较仓促,举办经验略有不足(快去鄙视小编~😒),但还是收到了10多位优秀的小伙伴共80篇博文(看看人家的劲头,这就是差距呀😓)的参赛作品投递; 其中初审最高…

    Linux干货 2016-06-07
  • 常见RAID级别

    什么是RAID?     独立磁盘冗余阵列(RAID,Redundant Arrary of Independent Disks),旧称廉价磁盘冗余阵列(Redundant Arrary of Inexpensive Disks),简称磁盘阵列。基本思想就是把多个相对便宜的硬盘组合起来,成为一个硬盘阵列组,使性能达到甚至超过一个价格昂贵、…

    Linux干货 2016-05-29
  • 8.1-用户和组(作业篇)

     1、将/etc/issue文件中的内容转换为大写后保存至/tmp/issue.out文件中。 [root@localhost ~]# tr a-z A-Z </etc/issue > /tmp/issue.out [root@localhost ~]#&n…

    Linux干货 2016-08-04