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

相关推荐

  • Linux权限管理练习

    1、当用户xiaoming对/testdir 目录无执行权限时,意味着无法做哪些操作? 无法cd切换进入此目录,无法创建文件,无法删除文件,无法查看里面文件的内容,只能ls列出目录下的内容 2、当用户xiaoqiang对/testdir 目录无读权限时,意味着无法做哪些操作? 无法ls查看目录下的内容 3、当用户wangcai 对/testdir 目录无写权…

    Linux干货 2016-08-05
  • iptables详解

    iptables命令: iptables [-t table] {-A|-C|-D} chain rule-specification iptables [-t table] -I chain [rulenum] rule-specification iptables [-t table] -R chain rulenum rule-specificatio…

    Linux干货 2017-11-12
  • linux学习的环境构建

    俗话说磨刀不误砍柴工,所以在加入马哥linux培训班后第一件事情就是构建学习环境。在这里把一些心得分享给大家。 1:通过测试比较服务器选择运行ESXI6.0的虚拟机。刚开始准备采用微软的Hyper-v的,但是管理Hyper-v需要域环境(工作组环境下虽然也可以管理,但是配置复杂和安全性很低),额外的增加了系统开销所以果断放弃。 2:通过网络获得Esxi6.0…

    Linux干货 2016-02-28
  • Linux基础知识(五)-文件查找命令find

    对grep 和 find 命令的操作 1、显示当前系统上root、fedora或user1用户的默认shell; 2、找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello(); 3、使用echo命令输出一个路径,使用grep取出其基名; 4、找出ifconfig命令结果中的1-255之间数字; 5、写一个…

    Linux干货 2016-10-24
  • 磁盘管理2

        centos6 实现loop 设备和文件关联         dd if=/dev/zero of=/testdir/bigfile bs=1M count=500      &nb…

    Linux干货 2016-09-01
  • 基础网络配置

    配置文件: /etc/ude /proc/sys/net/ipv4/ip_forward /etc/sysconfig/network-scripts/ifcfg-IFACE 网络配置文件 /etc/sysconfig/network-scripts/route-IFACE 路由配置文件 配置文件里的设置: DEVICE:此配置文件应用到的设备 HWADDR…

    Linux干货 2017-05-08