8.3上课练习及课下作业

练习


上课练习

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

能查看文件大小,不能进入此目录,不能在此目录创建文件
能看到目录中的内容,不能查看目录内的大小及属性,仅能查看目录的相关属性
[xiaoming@localhost ~]$ ll -d qin
drwxrwxrw-. 2 root root 6 8月   3 22:10 qin
[xiaoming@localhost ~]$ ll -a qin
ls: 无法访问qin/.: 权限不够
ls: 无法访问qin/..: 权限不够
总用量 0
d????????? ? ? ? ?            ? .
d????????? ? ? ? ?            ? ..
[root@localhost xiaoming]# su xiaoming
[xiaoming@localhost ~]$ cd qin
bash: cd: qin: 权限不够
[xiaoming@localhost ~]$ ll qin
总用量 0
[xiaoming@localhost ~]$ touch qin/asd
touch: 无法创建"qin/asd": 权限不够

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

可以进入目录,可以在目录中创建文件,无法查看目录里面的内容

[root@localhost qiuzhaoxian]# ll
总用量 2360
drwxrwx-wx. 3 xiaoming xiaoming      30 8月   4 19:15 123
[t1@localhost /]$ cd /123/
[t1@localhost 123]$ ll
ls: 无法打开目录.: 权限不够
[t1@localhost 123]$ touch asd
[t1@localhost 123]$ echo dsad > asd
[t1@localhost 123]$ ll -d /123
drwxrwx-wx. 3 xiaoming xiaoming 40 8月   4 19:19 /123

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

不能修改和删除

[wangcai@localhost ~]$ echo hello > /testdir/file1
-bash: /testdir/file1: Permission denied
[wangcai@localhost ~]$ echo hello >> /testdir/file1           不能修改
-bash: /testdir/file1: Permission denied
[wangcai@localhost ~]$ rm /testdir/file1
rm: cannot remove ‘/testdir/file1’: Permission denied         不能删除

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

[root@localhost /]# cp /etc/fstab  /var/tmp/
[root@localhost /]# chown wangcai:sysadmins /var/tmp/fstab 
[root@localhost /]# ll /var/tmp/fstab
-rw-r--r--. 1 wangcai sysadmins 501 8月   4 19:32 /var/tmp/fstab
[root@localhost /]# chmod 660 /var/tmp/fstab
[root@localhost /]# ll /var/tmp/fstab
-rw-rw----. 1 wangcai sysadmins 501 8月   4 19:32 /var/tmp/fstab

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

mkdir /home/wangcai
cp -r /etc/skel/. /home/wangcai
chmod 700 /home/wangcai/

作业

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

[root@localhost ~]# mkdir -p /data/testdir 
[root@localhost ~]# groupadd g1
[root@localhost ~]# groupadd g2
[root@localhost ~]# groupadd g3
[root@localhost ~]# cd /data
[root@localhost data]# chgrp g1 testdir/
[root@localhost data]# chmod 2770 testdir/
[root@localhost data]# ll -d testdir/     
drwxrws---. 2 root g1 6 Aug  3 19:15 testdir/
[root@localhost data]# setfacl -m g:g2:rwx testdir/    //设置g2组用户对testdir目录有权限
[root@localhost data]# setfacl -m g:g3:rwx testdir/    //设置g3组对testdir目录有权限
[root@localhost data]# setfacl -m d:g:g2:rw testdir/ 设置默认g2组内成员对目录内操作的权限
[root@localhost data]# setfacl -m d:g:g3:r testdir/
[root@localhost data]# gpasswd -a alice g2
Adding user alice to group g2
[root@localhost data]# gpasswd -a tom g3
Adding user tom to group g3
[root@localhost data]# su alice
[alice@localhost data]$ cd testdir/
[alice@localhost testdir]$ touch f
[alice@localhost testdir]$ getfacl f
# file: f
# owner: alice
# group: g1
user::rw-
group::rwx                      #effective:rw-
group:g2:rw-
group:g3:r--
mask::rw-
other::---

设置/testdir/f1的权限,使user1用户不可以读写执行,g1组可以读写/testdir/dir的权限,
使新建文件自动具有acl权限:user1:rw,g1:—
备份/testdir目录中所有文件的ACL,清除/testdir的所有ACL权限,并利用备份还原

   touch f1
   setfacl -m u:user1:0 f1 
   setfacl -m g:g1:rw f1  
   setfacl -m g:g1:rwx /testdir
   setfacl -m u:user1:rwx /testdi
   setfacl -m d:u:user1:rw /testdir/
   setfacl -m d:g:g1:- /testdir/
   getfacl ../testdir/
   getfacl /testdir/f1 
   getfacl -R ../testdir/ >acl.sql
   setfacl -R -b /testdir
   setfacl -R --set-file=acl.sql /testdir/
   getfacl /testdir/

原创文章,作者:qzx,如若转载,请注明出处:http://www.178linux.com/29194

(0)
qzxqzx
上一篇 2016-08-05 10:17
下一篇 2016-08-05 10:17

相关推荐

  • LVS-net模型

    net模型拓扑图 注:rip的网关需指向DIP 搭建LVS net模式 基于httpd服务 首先准备三台主机 主机A 主机B 主机C 主机A(vs主机) 主机A设置两个IP 一个内网一个外网 #yum -y install ipvsadm #echo 1 > /proc/sys/net/ipv4/ip_forward :打开核心转发功能 #iptabl…

    Linux干货 2017-05-17
  • 三台主机部署phpwind

    PHPWind(简称:PW)的使命是让网站更具价值,让更多人从网络中享受便利,以提升生活品质。 phpwind是一个基于PHP和MySQL的开源社区程序,是国内最受欢迎的通用型论坛程序之一。phpwind第一个版本ofstar发布于2004年。截止2013年12月phpwind项目品牌由阿里云计算有限公司拥有,软件全面开源免费。 特点 1. 非凡的访问速度 …

    2017-06-13
  • 跟我一起学man page、history的使用,剖析FHS(文件系统目录标准)

    跟我一起学man page、history的使用,剖析FHS(文件系统目录标准) 描述 从Linux小白鼠成长为高(lao)高(hei)手(shu)的过程中,无论如何都要学会自个儿施法解决问题,法力的高深体现了解决问题的能力,这里的法力指的是在没有互联网的环境下如何使用man page或相关文档找到命令的使用方法和配置文件的修改方法。本文第一部分总结了在Li…

    Linux干货 2016-07-29
  • 计算机的组成及功能

    计算机的组成有中央处理器(包含逻辑运算器和控制器)、内存、输入设备、输出设备    逻辑运算器主要负责程序的运算和逻辑的判断、控制器是协调各组件与各单元的工作。 内存是与CPU进行沟通的桥梁,其作用是用于暂时存放CPU中的运算数据,以及与硬盘等外部存储器交换的数据。 输入设备是用户和计算机系统之间进行信息交换的主要装置之一。 输出设备是外…

    Linux干货 2017-07-02
  • 第七周

    1、创建一个10G分区,并格式为ext4文件系统;    (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; 第一步先在磁盘上创建分区:fdisk /dev/sdc n –> e –> 5 –> default &#…

    Linux干货 2017-05-18
  • shell脚本作业

    1、编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名, IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小。 脚本代码 #!/bin/bash #author:wzc         echo Hostname:…

    Linux干货 2016-08-15