2018/8/3作业

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

groupadd g1                                 #创建g1组
groupadd g2                                 #创建g2组
groupadd g3                                 #创建g3组
makdir /data/testdir                        #创建/data/testdir目录
chmod g+s /data/testdir                     #给目录添加sgid权限
chmod g=rwx o= /data/testdir                #更改目录属组权限为读写执行,其他人无权限
chown :g1 /data/testdir                     #更改/data/testdir属组为g1
setfacl -m u:alice:rwx /data/testdir        #为目录设置alice的读写执行的facl权限
setfacl -m g:g3:rx data/testdir             #设置目录的组针对g3的facl权限

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

对于文件
        r:可获取文件的数据
            通常是对文本文件有意义,对于二进制文件无意义。

        w:可修改文件的数据
            有写权限但是不能删除文件,但是可以清空文件。

        x可将此文件运行为进程,普通文件没有执行权限,也不应该有执行权限。
        执行权限通常针对于可执行文件和脚本文件

对于目录:
    对于目录一般给的全显示r-x或rwx或---

        r:可使用ls命令获取其下的所有文件列表,但是不能访问文件,不能cd,也不能查看文件的元数据,不支持ls -l不能查看文件的元数据。

        只有读权限
            [user2@localhost ~]$ ll /testdir/
            ls: cannot access /testdir/file3: Permission denied
            ls: cannot access /testdir/file2: Permission denied
            ls: cannot access /testdir/file1: Permission denied
            ls: cannot access /testdir/file4: Permission denied
            total 0
            -????????? ? ? ? ?            ? file1
            -????????? ? ? ? ?            ? file2
            -????????? ? ? ? ?            ? file3
            -????????? ? ? ? ?            ? file4

        w:可以获取此目录下的文件列表,即创建删除文件
            只有写权限
                    可以获取目录的列表但是不能使用ls -l,不能创建和删除文件。
            有写和执行的权限
                    可创建,删除文件。但是不能获取目录的文件列表
                    [user1@localhost ~]$ chmod 703 /testdir/

                    [user2@localhost testdir]$ touch /testdir/user2-file
                    [user2@localhost testdir]$ cd /testdir/
                    [user2@localhost testdir]$ ls
                    ls: cannot open directory .: Permission denied
                    [user2@localhost testdir]$ ll -d /testdir/
                    drwx----wx 2 user1 user1 4096 Jul 25 11:39 /
        x:可以cd至此目录中,可使用ls -l

            没有执行权限即使用户有写和读的权限依然不能操作目录下的文件。不能删除更改内容。x代表可以进入目录中。
            只有执行权限,仅是可以cd进目录,不能查看目录列表,不能使用ls -l,可以访问目录下的文件,可以追加内容(写入),但是不能删除文件。

umask和acl mask 的区别和联系

设置了mask后,除所有者其他人以外的用户和组的facl权限都不能大于mask,可以小于等于,但是更改group的权限后就会更改mask值。

与umask的区别。umask的值是用户不能默认创建文件的权限,并且权限必须是用777或666减去umask的值,精确匹配。不能小于更不能有与umask一样的权限,必须等于。

    相同点:都是限制用户权限

        umask限制用户新建文件的默认权限。
        mask限制除所有者和其他人以外的人的权限。

    不同点:严格程度不同。

        umask严格限制用户的权限精确到三位全部权限。
        mask除所有者和其他人以外的用户和组的权限可以小于等于mask但是不能多于mask

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

suid

功能:
    用户运行某程序时,如果此程序拥有SUID的权限,程序以其属主身份运行

应用场景:需要使用所有者身份运行但是不希望,其他人或组成员将系统环境切换至所有者身份运行。系统只有少量特殊程序如passd具有该权限。这是一个比较危险的操作。不建议将某些程序设置suid特别属主是root的。

sgid

功能:
    1、作用于目录
    一般用户创建目录时应用此权限的目录,其他用户在此目录下创建文件的属组为SGID组。不是用户的主组

    2、作用在二进制文件
    是以进程发起者的身份运行。只是该进程继承了该程序属组的权限。
    该程序,访问文件时,所有者不匹配,开始匹配所属组。匹配的是进程的属组,而不是进程发起者的基本组。

应用场景:
        作用于目录的应用,便于同一组内成员之间的文件更改使用。可以只是同一组内成员间的读写执行。其他用户可以无权限。

sticky

功能:
    对于属组或全局可写的目录组内的所有用户或系统上的所有用户在此目录中都能创建新文件或删除文件;如果为此类目录设置sticky权限,则每个用户能创建文件,且只能删除自己的文件。

应用场景:
    防止同一组下成员误删除同组人员的文档,尽管可以没有同组成员之间没有写权限,但是可以删除、覆盖。

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

umask 177 临时生效,仅对当前shell有效。
更改~/.bashr或~/.bash_profile 写入umask 177

设置/testdir/f1的权限,使user1用户不可以读写执行,g1组可以读写 /testdir/dir的权限,使新建文件自动具有acl权限:user1:rw,g1:— 备份/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::rwx
    other::---
    default:user::rwx
    default:user:user1:rw-
    default:group::rwx
    default:group:g1:---
    default:mask::rwx
    default:other::---

    [root@localhost ~]# getfacl /testdir/f1 
    getfacl: Removing leading '/' from absolute path names
    # file: testdir/f1
    # owner: root
    # group: g1
    user::rw-
    user:user1:---
    group::r--
    group:g1:rw-
    mask::rw-
    other::r--

备份acl

    [root@localhost ~]# getfacl /testdir/* > /testdir/acl.txt
    getfacl: Removing leading '/' from absolute path names
    [root@localhost ~]# ll /testdir/
    total 4
    -rw-rw----+ 1 root g1 116 Jul 25 13:19 acl.txt
    -rw-rw-r--+ 1 root g1   0 Jul 25 13:13 f1
    [root@localhost ~]# cat /testdir/acl.txt 
    # file: testdir/f1
    # owner: root
    # group: g1
    user::rw-
    user:user1:---
    group::r--
    group:g1:rw-
    mask::rw-
    other::r--

删除acl

    [root@localhost ~]# setfacl -Rb /testdir/
    [root@localhost ~]# getfacl /testdir/
    getfacl: Removing leading '/' from absolute path names
    # file: testdir/
    # owner: root
    # group: g1
    # flags: -s-
    user::rwx
    group::rwx
    other::---
    [root@localhost ~]# getfacl /testdir/f1 
    getfacl: Removing leading '/' from absolute path names
    # file: testdir/f1
    # owner: root
    # group: g1
    user::rw-
    group::r--
    other::r--

恢复权限

    [root@localhost ~]# setfacl -M /testdir/acl.txt /testdir/

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

(0)
yywyyw
上一篇 2016-08-04
下一篇 2016-08-05

相关推荐

  • bash脚本编程class3

    bash脚本编程class3—函数定义与数组使用相关     一.函数的使用以及数组的定义   我们通过学习知道,当编辑一个shell脚本的时候,可以在这个shell脚本中调用其他的shell脚本来实现特定的功能。在实际工作环境中,用很多shell实现的功能是我们常常使用到的,如果一次一次的调用这些shell脚本会显得非常麻烦。…

    Linux干货 2016-08-24
  • M20-1权限作业

    1、当用户xiaoming对/testdir 目录无执行权限时,意味着无法做哪些操作? [root@centos7 testdir]# ls -ld /testdir/ drwxr-xrw-. 3 root root 27 Aug  5 0…

    Linux干货 2016-08-05
  • 第六周课程作业

    1、复制/etc/rc.d/init.d/functions文件至/tmp目录,将/tmp/functions文件中 的以至少一个空白字符开头的行的行首加# ~]# cp /etc/rc.d/init.d/functions /tmp~]# vim /tmp/functions %s@^[[:space:]]\+@#@g 2、复制/boot/gru…

    Linux干货 2016-12-12
  • Linux文本处理及用户组管理命令练习

    一.文本处理基础命令 (1).  列出当前系统上所有已经登录的用户的用户名。           完成命令:who  |  cut  -d’ ‘  -f1  |  uniq  -u 示例: (2).取出最后登录到当前系统对的用户的相关信息。         完成命令:w  |  tail -1 示例: (3).取出当前系统上被用户当作…

    2018-03-11
  • 第七周

    1、创建一个10G分区,并格式为ext4文件系统; (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; fdisk /dev/sdb欢迎使用 fdisk (util-li…

    Linux干货 2016-09-19
  • sed工具

    sed是一种流编辑器,它是文本处理中非常中的工具,能够完美的配合正则表达式使用,功能不同凡响。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(patternspace),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有 改变,除非你使用重定向存储输出。Sed主要用来…

    2017-08-26