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

相关推荐

  • find命令基本应用

       简单的find命令查找 Find +路径+条件(支持文件通配)+找到后执行的操作 条件: 可根据文件类型查找:-type   f为普通文件 d为目录文件 l为链接文件(常用) 可根据属主和属组查找:-uid  -gid 可根据时间戳来查找:alime(查看时间)ctime(文件属性更改时间)m…

    Linux干货 2017-04-11
  • 3.用户和组管理

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@localhost ~]# who root     tty1         2016-12-…

    Linux干货 2017-07-16
  • http特性

    一、何为http 什么是http?http是Hyper Text Mark Language的缩写,超文本标记语言。Apache下的httpd是实现了这一功能的开源软件。 二、http特性 http特性1:持久连接及MPM参数设置 KeepAlive {On|Off} #是否启动持久连接 MaxKeepAliveRequests 100 …

    Linux干货 2015-10-15
  • RAID(重要)

    RAID   RAID(Redundent Array of Independent Disk):独立的冗余磁盘阵列,目的是为了结合多个物理驱动器组成单个单元,提高了磁盘的性能或保证数据冗余。RAID能够防止硬件的故障导致数据丢失,但是不能防止人为操作,软件故障、恶意软件感染等造成的数据丢失,因此不能替代备份。 分类有:硬件实现RAID(一是外接式磁盘阵列柜…

    Linux干货 2016-08-30
  • keepalived+varnish+haproxy+LNAMP

      nfs: 192.168.1.40 rp1: 192.168.1.41 rp2: 192.168.1.42 mariadb: 192.168.1.43 web1: 192.168.1.110 web2: 192.168.1.111 app1: 192.168.1.112 app2: 192.168.1.113 实验效果:用keepalived高…

    2018-02-18
  • LVS负载均衡实战演练

    LVS负载均衡实战之lvs-nat模型 1.准备好机器,配置好时间同步,配置号网络,主机名 172.16.251.91 client [桥接] [网关为172.16.251.90] #lvs负载均衡两块网卡 172.16.251.90  lvs [网卡1] [桥接] 192.168.42.150  lvs [网卡2] [VMnet8] 192.168.42.…

    Linux干货 2017-06-22