20160803用户权限作业

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

文件:r:可以cat查看文件中的内容,可以查看文件的属性

         w:可以ll查看文件的属性,也可以往文件中写入内容,如果其父目录具有写和执行权限就可删除其内部文件

          x:针对二进制程序或脚本,没有读权限也可以执行二进制

目录:

          r:可以ls查看文件,看不到权限等元数据,不能cd进不去目录

         w:可以创建或删除目录中的文件,但需要配合x使用

          x:可以进入目录,可以访问目录中的文件

  注意:只要对目录写和执行,就可以删除目录中的文件

 

2.umask和acl mask的区别和联系

        umask是针对管理员和普通用户设置的权限,管理员默认时022,普通用户时002,当我们在配置文件中配置umask的值时,就可以定义用户创建文件或目录时的默认权限,也可以说是限制了ugo的权限。

                管理员文件的权限和umask的关系为:666-022=644,如果计算结果中有基数,则加1,例如666-123=543 ->644

                管理员目录的权限和umask的关系为:777-022=755

        mask是在指定给某些用户或者组设置ACL权限时,针对除了属主和other之外的人,其中包括属组和添加ACL的用户和组,限制了他们的权限,不能超过mask的权限,mask在使用时需要注意的是,当我们设置了ACL权限时,如果设置组的权限chmod g=rw file|dir,等同于设置了mask的权限,此时所有设置了ACL权限的人和文件或目录的数组都会改变。


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

    文件的特殊权限

        suid

            面向对象:二进制程序  chmod u+s file

            作用:用户发起进程访问文件时,不在是以用户自己的身份来访问,而是以进程属主的身份来访问。        

            应用场景:passwd 所有用户都需要执行的二进制程序,直接给管理员的程序,不用单独给某些用户添加加权限。

             -rwsr-xr-x. 1 root root 30768 11月 24 2015 /usr/bin/passwd   —–此时我们就是以passwd的数主roor身份运行。

        sgid

             面向对象:文件、目录  chmod g+s file | dir

             作用:

                    目录:用户在该目录下创建文件时,文件的属组不在是以自己的身份创建,而是以该目录数组的身份创建。

                    文件:用户发起进程访问文件时,不在是以用户自己的身份来访问,而是以进程属组的身份来访问。

             应用场景:

                    目录:比如组内同事,以某一特定的权限共享将一些文件或目录给大家,这样避免单独给多个文件分别设置权限。

                    文件:

        sticky

            面向对象:目录

            作用:用户在该目录下可以自由的创建改文件,但是不能删除非自己创建的文件

            应用场景:/tmp 所有用户都可以编辑,但是不能删除别人的文件

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

1        [user1@cenots6 ~]$ touch a        
2        [user1@cenots6 ~]$ ll a
3        -rw-rw-r--. 1 user1 user1 0 8月   4 23:49 a
4        [user1@cenots6 ~]$ echo umask 066 >> .bashrc 
5        [user1@cenots6 ~]$ source .bashrc 
6        [user1@cenots6 ~]$ touch b
7        [user1@cenots6 ~]$ ll b
8        -rw-------. 1 user1 user1 0 8月   4 23:50 b

     

5.设置/testdir/f1的权限,使user1用户不可以读写执行,g1组可以读写

           setfacl -m u:user1:0,g:g1:rw /testdir/f1

  /testdir/dir的权限,使新建文件自动具有acl权限:user1:rw,g1:—备份/testdir目录中所有文件的ACL

           setfacl -m d:u:user1:rwx,g:d:g1:rwx /testdir/dir
           setfacl -m d:u:user1:rw,g:d:g1:0 /testdir/dir

   清除/testdir的所有ACL权限,并利用备份还原    

                   getfacl -R /testdir >acl.txt                   
                   setfacl -R -b /testdir
                   setfacl -R -set-file=acl.txt /testdir 
                   getfacl -R /testdir

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

        解题思路:

                    新建文件自动属于g1组–>对目录加sgid权限

                    g2组成员对新文件有读写权限–>首先要对目录有rwx权限,否则,不能进入目录更不能读写目录中的内容

                    其它用户不能访问这个文件夹–> 需要将other设置为0即可

        设置如下:

                       root@cenots6.8  /testdir # chown :g1 /testdir/     
                       root@cenots6.8  /testdir # chmod 2770 /testdir/                                                                         
                       root@cenots6.8  /testdir # ll -d /testdir/                                                                                                                    
                       drwxrws---. 2 root g1 4096 8月   6 16:13 /testdir/
                       root@cenots6.8  /testdir # setfacl -m g:g2:rwx /testdir/
                       root@cenots6.8  /testdir # setfacl -m g:g3:rwx /testdir/
                       root@cenots6.8  /testdir # setfacl -m d:g:g2:rwx /testdir/
                       root@cenots6.8  /testdir # setfacl -m d:g:g3:r /testdir/
                       root@cenots6.8  /testdir # getfacl /testdir/
                       getfacl: Removing leading '/' from absolute path names
                        # 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:rwx
                        default:group:g3:r--
                        default:mask::rwx
                        default:other::---
                        root@cenots6.8  /testdir # gpasswd -a alice g2   ---alice 加入到g2 组中,读写aa文件成功
                        正在将用户“alice”加入到“g2”组中
                        root@cenots6.8  /testdir # touch aa
                        root@cenots6.8  /testdir # su alice
                        alice@cenots6.8  /testdir # cat aa
                        alice@cenots6.8  /testdir # echo hello >>aa
                        root@cenots6.8  /testdir # gpasswd -a tom g3  ---将alice加入到g3组中,可以读不能写,满足条件
                        正在将用户“tom”加入到“g3”组中
                        root@cenots6.8  /testdir # su tom
                        tom@cenots6.8  /testdir # cat aa
                        hello
                        tom@cenots6.8  /testdir # echo hello>>aa
                        bash: aa: 权限不够                                        
                        tom@cenots6.8  /testdir # rm aa
                        rm:是否删除有写保护的普通文件 "aa"?y--->此时tom可以删除/testdir中的内容,原因:组对目录有wx权限
                        tom@cenots6.8  /testdir #

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

              不能:cd               ll /testdir/file1

                  能:ls /testdir   ll /testdir 

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

              不能:l1 /testdir/

                 能:cd  touch mkidr            

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

                不能修改和删除

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

                   cp /etc/fstab /var/tmp                    
                   chown wangcai:sysadmins /var/tmp/fstab
                   chmod o= /var/tmp/fstab

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

                    useradd  wangcai                 
                    rm -rf ~wangcai
                    mkdir /home/wangcai
                    chown wangcai:wangcai /home/wangcai
                    chmod 700 /home/wangcai
                    cp -r  /etc/skel/. ~wangcai

                                        

                    

                        

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

(0)
NarutoNaruto
上一篇 2016-08-07
下一篇 2016-08-07

相关推荐

  • 马哥教育网络班21期+第4周课程练习

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 # cp -a /etc/skel /home/tuser1 # chmod -R g-rwx,o-rwx /home/tuser1/ 2、编辑…

    Linux干货 2016-07-16
  • 计算机网络基础

    1、OSI, TCP/IP, 五层协议的体系结构, 以及各层协议 OSI分层(7层): 物理层, 数据链路层, 网络层, 传输层, 会话层, 表示层, 应用层 TCP/IP分层(4层): 网络接口层, 网际层, 传输层, 应用层 五层协议(5层): 物理层, 数据链路层, 网络层, 运输层, 应用层 每一层的协议: 物理层: RJ45, CLOCK, IEE…

    Linux干货 2016-09-19
  • 选择判断专题脚本编程_第九周练习

    Q1:写一个脚本,判断当前系统上所有用户的shell是否为可登录shell(即用户的shell不是/sbin/nologin);分别这两类用户的个数;通过字符串比较来实现; #!/bin/bash # declare -i y=0 declare -i n=0 for i in $(cut…

    Linux干货 2016-12-25
  • Linux之数组

      Linux之数组     数组介绍数组:存储多个元素的连续的内存空间,相当于多个变量的集合。 变量:存储单个元素的内存空间数组名和索引索引:编号从0开始,属于数值索引注意:索引可支持使用自定义的格式,而不仅是数值格式,即为关联索引,bash4.0版本之后开始支持。bash的数组支持稀疏格式(索引不连续)声明数组:de…

    Linux干货 2016-08-25
  • ELK+RabbitMQ架构处理nginx及tomcat日志

    前言       查看日志的传统方法是:登录操作系统,使用命令工具如cat、tail、sed、awk、grep等等进行过滤输出后分析,处理少量日志还好,日志量大处理效率就没那么高了。而且很多情况下开发人员需要查看并分析日志进行排错,但他们对Linux命令又不是太熟悉,而且有时候又不能赋予他们服务器权限,更多时…

    Linux干货 2016-08-02
  • CentOS下搭建LAMP

    实验:centos7.3实现lamp应用wordpress环境 host1 httpd,php  host2 mariadb1 yum install httpd php php-mysqlyum install mariadb-serversystemctl start httpdsystemctl start mariadb 2 创建数据库及用户mysq…

    2017-10-16

评论列表(1条)

  • 马哥教育
    马哥教育 2016-08-07 23:00

    文章对特殊权限的用法及应用场景有了完整的总结,如果能在文章中加入自己练习过程中的模拟场景在以后的复习过程中会看起来更直观哦。