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

(0)
上一篇 2016-08-04 21:40
下一篇 2016-08-04 21:40

相关推荐

  • iptables/netfilter基于layer7实现应用层过滤

    前言 做为网络管理员,对P2P、QQ、酷狗等软件是又爱又恨,大多数公司为了提高工作效率,禁止公司员工登陆QQ、看视频等,在市场上买专门的上网行为管理设备,随便一种都是价格不菲,而使用linux来做网关一样可以禁止qq、酷狗等软件,为实现此功能就需要为iptables/netfilter添加layer7模块,而iptables/netfilter是基于内核的,…

    Linux干货 2015-04-27
  • 四大开源协议比较:BSD、Apache、GPL、LGPL

          现今存在的开源协议很多,而经过Open Source Initiative组织通过批准的开源协议目前有58种。我们现在常见的开源协议如BSD, GPL, LGPL,MIT等都是OSI批准的协议。如果要开源自己的代码,最好也是选择这些被批准的开源协议。   这里我们来看四种最常用的开源协议及它们的适用范围,供那些准备开…

    系统运维 2016-08-15
  • Linux系统程序包的安装–RPM

           我们知道在操作系统上使用的程序都是有程序员通过开发工具得来的,程序员直接编写的纯文本的文件,我们称之为源代码,由于计算机识别的是二进制程序,因此在完成源代码编写之后,就必须要经过编译,使之成为操作系统可以“看得懂”的二进制程序,这里的编译是通过编译器来进行的操作,编译器的功能就是将源代码程序“转换”为二进…

    2017-04-23
  • DNS实验

      建立DNS服务器(正向解析) linux没有缓存 windows有dns缓存 权威结果,非权威结果 无论是正向解析数据库还是反向解析数据中  写管理员邮件地址或完整域名(FQDN)都要再后面加上点。否则系统会自动不上区域名称。 实验环境先清理防火墙规则,关闭防火墙. centos7 systemctl disabl…

    Linux干货 2016-11-01
  • 正则表达式、扩展正则表达式

    正则表达式:支持:grep,sed,awk,vim, less,nginx,varnish等

    2018-03-16
  • PXE网络引导系统自动化安装CentOS7

     一.PXE 注意:安装前 selinux 禁用,iptables 关闭 dhcp 服务器静态IP地址  1.PXE的工作原理:      Client向PXE Server上的DHCP发送IP地址请求消息,DHCP检测Client是否合法(主要是检测Client的网卡MAC  &nbsp…

    Linux干货 2017-07-24