M20 – 1- 第三周(2):课堂练习与作业

课堂练习:

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

[root@centos6 ~]# groupadd g1
[root@centos6 ~]# groupadd g2
[root@centos6 ~]# groupadd g3
[root@centos6 ~]# useradd -G g2 alice
[root@centos6 ~]# useradd -G g3 tom
[root@centos6 ~]# id alice
uid=501(alice) gid=504(alice) groups=504(alice),502(g2)
[root@centos6 ~]# id tom
uid=502(tom) gid=505(tom) groups=505(tom),503(g3)
[root@centos6 ~]# mkdir -p /data/testdir
[root@centos6 ~]# cd /data/
[root@centos6 data]# ll
total 4
drwxr-xr-x. 2 root root 4096 Aug  6 19:06 testdir
[root@centos6 data]# chgrp g1 testdir/
[root@centos6 data]# chmod g+sw,o= testdir/
[root@centos6 data]# ll
total 4
drwxrws---. 2 root g1 4096 Aug  6 19:06 testdir
[root@centos6 data]# setfacl -m g:g2:rwx,g:g3:rwx testdir/
[root@centos6 data]# setfacl -m d:g:g2:rw,d:g:g3:r testdir/
[root@centos6 data]# getfacl testdir/
# file: testdir/
# owner: root
# group: g1
# flags: -s-
user::rwx
group::rwx
group:g2:rwx
group:g3:rwx
mask::rwx
other::---
default:user::rwx
default:group::rwx
default:group:g2:rw-
default:group:g3:r--
default:mask::rwx
default:other::---

[root@centos6 data]#

作业:

1、设置user1,使之新建文件权限为rw——-

[user1@centos6 ~]$ echo "umask 0066" >> .bashrc 
[user1@centos6 ~]$ . .bashrc
[user1@centos6 ~]$ umask
0066
[user1@centos6 ~]$ touch file1
[user1@centos6 ~]$ ls -l file1 
-rw-------. 1 user1 user1 0 Aug  6 19:16 file1
[user1@centos6 ~]$

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

[root@centos6 testdir]# ls -ld .
drwxr-xr-x. 2 root root 4096 Aug  6 20:25 .
[root@centos6 testdir]# mkdir -p /testdir/dir/
[root@centos6 testdir]# touch f1
[root@centos6 testdir]# setfacl -m u:user1:0,g:g1:rw /testdir/f1
[root@centos6 testdir]# setfacl -m d:u:user1:rw,d:g:g1:0 /testdir/dir/
[root@centos6 testdir]# getfacl -R * > /root/acl.txt
[root@centos6 testdir]# setfacl -R --set-file=/root/acl.txt /testdir/dir

3、三种权限rwx对文件和目录的不同意义

文件的权限意义

r: 可使用文件查看类工具获取其内容;
w: 可修改其内容;
x: 可以把此文件提请内核启动为一个进程

目录的权限意义

r: 可以使用ls查看此目录中文件列表;
w: 可在此目录中创建文件,也可删除此目录中的文件;
x: 可以使用ls -l查看此目录中文件列表,可以cd进入此目录;

4、umask和acl mask 的区别和联系

umask:从目录或文件上屏蔽掉最大权限相应的位,从而得出默认权限
acl:为指定用户或用户组添加权限
mask:控制acl列表中用户的最高权限

5、三种特殊权限的应用场景和作用

SUID

作用:任何一个可执行程序文件能不能启动为进程:取决发起者对程序文件是否拥有执行权限,启动为进程之后,其进程的属主为原程序文件的属主
场景:启动为进程之后,其进程的属主为原程序文件的属主,SUID只对二进制可执行程序有效,SUID设置在目录上无意义

SGID

作用:任何一个可执行程序文件能不能启动为进程:取决发起者对程序文件是否拥有执行权限;启动为进程之后,其进程的属主为原程序文件的属组
场景:默认情况下,用户创建文件时,其属组为此用户所属的主组;一旦某目录被设定了SGID,则对此目录有写权限的用户在此目录中创建的文件所属的组为此目录的属组;通常用于创建一个
协作目录

SGID

作用:具有写权限的目录通常用户可以删除该目录中的任何文件,无论该文件的权限或拥有权
场景:在目录设置Sticky 位,只有文件的所有者或root可以删除该文件;sticky 设置在文件上无意义

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

(0)
AleenAleen
上一篇 2016-08-08 16:15
下一篇 2016-08-08 16:15

相关推荐

  • linux文件系统分类

    1、linux文件系统分配策略: 块分配(blockallocation)和扩展分配(extentallocation): 块分配:磁盘上的文件块根据需要分配给文件,避免了存储空间的浪费。但当文件扩充时,会造成文件中文件块的不连续,从而导致过多的磁盘寻道时间。 每一次文件扩展时,块分配算法就需要写入文件块的结构信息,也就是meta-dada。meta-dat…

    Linux干货 2017-05-02
  • 在VMware上安装CentOS 6 教程

    一、下载并安装虚拟机软件VMware Workstation 14 下载地址: https://www.vmware.com/products/workstation-pro/workstation-pro-evaluation.html 下载完成后,从网上搜一个注册码来安装注册 二、下载CentOS 6.9安装镜像 下载地址: http://mirrors…

    2018-03-29
  • yum与rpm包

    yum与rpm包 包命名和工具 包:分类和拆包 Application-VERSION-ARCH.rpm:主包 Application-devel-VERSION-ARCH.rpm 开发子包 Application-utils-VERSION-ARHC.rpm 其它子包 Application-libs-VERSION-ARHC.rpm 其它子包 包之间:可…

    Linux干货 2017-05-08
  • Linux基于PXE实现系统全自动无人值守安装

    前言 在生产环境中,我们时常会需要在多台客户端主机或服务器安装操作系统,如果每一台都去手动安装,费时费力,显然是不现实的。那么,如何高效的完成此类工作呢?文将讲解如何实现Linux系统的全自动无人值守安装。 提供PXE服务所需安装包 dhcp:动态主机配置协议,给客户端提供ip地址 tftp-server:tftp服务器端,提供系统安装所需文件 xinetd…

    Linux干货 2015-04-01
  • 高级文件系统的管理

    一、迁移分区 分区 /dev/sda6 注意同步问题  创建分区,把原先家目录下的文件拷贝到新挂载的文件中 mkfs.ext4 /dev/sda6  mkdir /mnt/home mount /dev/sda6 /mnt/home cp -a /home/*  /mnt/home   init 1 切换单用户模式,把…

    Linux干货 2016-11-27
  • 马哥教育网络班21期+第2周课程练习

    一:在Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例。     在Linux中,文件管理类命令主要有cp,mv,rm三个     其中cp命令的使用格式如下:           …

    Linux干货 2016-07-16