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)
上一篇 2016-08-07 22:06
下一篇 2016-08-07 22:06

相关推荐

  • 文本处理-三剑客-grep

    文本过滤
    grep [OPTIONS] PATTERN [FILE…]

    2018-03-16
  • ubuntu kylin虚拟机安装KVM

    1.确定物理机CPU是否支持虚拟化    查看方法1:计算机->属性->处理器(Inter(R) Core(TM) i5-2450M),然后去网上查看自己的电脑CPU是否支持虚拟化,    地址http://ark.intel.com/zh-cn/找到自己CPU的信息,虚拟化技术后是否显示为yes,如果是n…

    Linux干货 2016-10-15
  • 0809linux基础小记(sed和vim用法)

    sed  [options] ‘scripts’ inputfile -n: 不输出模式空间内容的自动打印 -e: 多点编辑 -f:从指定文件中读取编辑脚本 -i:原处编辑 scripts: ’地址命令’ 地址定界: (1)  不给地址:对全文进行处理 (2)  单地址: #:  指定的行 例: sed '2…

    Linux干货 2016-08-11
  • LAMP的编译安装

    一、编译安装amp: (1)系统环境:centos6,7 httpd依赖于apr和apr-util appache protable runtime (2)开发环境: Development Tools,Server Platform Development (3)各程序的版本: httpd:2.2,2.4 php:5.x mysql:5.1,5.5,5.6…

    Linux干货 2016-10-17
  • N22-℡浮生.若夢 ╮第七周作业

    1、创建一个10G分区,并格式为ext4文件系统; (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; ~]# mke2fs -t mkfs.ext4 -b 2048 -L MYDATA -m 2 /…

    Linux干货 2016-11-14
  • 网络管理之网络配置与网络组

    网络属性配置 回顾: TCP/IP协议栈:物理层,数据链路层,网络层,传输层,应用层,     链路数据层:以太网帧     网络层:IP报文      传输层:TCP,UDP     应用…

    Linux干货 2016-09-06

评论列表(1条)

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

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