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

相关推荐

  • etc的常见问答

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 [root@localhost tuser1]# cp -r /etc/skel/ /home/tuser1 [root@localhost tuser1]# chmod -R go= /home/tuser1/ [root…

    2017-12-26
  • class15磁盘管理(二) 高级磁盘管理(一)

    挂载点和/etc/fstab 配置文件系统体系 被mount、fsck和其它程序使用 系统重启时保留文件系统体系 可以在设备栏使用文件系统卷标 使用mount -a命令挂载  /etc/fstab 中的所有文件系统 文件挂载配置文件 /etc/fstab每行定义一个要挂载的文件系统;   &nbsp…

    Linux干货 2016-09-05
  • centos进程管理

    一 、进程的概念和分类1.进程的概念      Linux是一个多用户多任务的操作系统。多用户是指多个用户可以在同一时间使用同一个linux系统;多任务是指在Linux下可以同时执行多个任务,更详细的说,linux采用了分时管理的方法,所有的任务都放在一个队列中,操作系统根据每个任务的优先级为每个任务分配合适…

    Linux干货 2016-09-19
  • 2

    2

    Linux干货 2018-03-26
  • shell编程进阶

    2、编写脚本/root/bin/yesorno.sh,提示用户输入yes或no,并判断用户输入的是yes还是no,或是其它信息 read -p “Enter you choice yes|no:” Choice Choice1=`echo $Choice | tr ‘[a-z]’ ‘[A-Z]&#8…

    2017-09-16
  • Linux – 计算机基础知识体系

    一、认识计算机的组成      计算机组成(computer composition)指的是系统结构的逻辑实现,包括机器机内的数据流和控制流的组成及逻辑设计等。 计算机一般是由硬件系统和软件系统这两部分组成,硬件系统包括:CPU、内存、硬盘、输入和输出设备(键盘鼠标、显示器等),软件系统包括:系统软件自身、用…

    Linux干货 2017-02-19