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

相关推荐

  • CentOS 7上配置php-fpm

    CentOS 7上配置php-fpm:              httpd-2.4:rpm包默认编译支持了fcgi模块;              php-fpm包:专用于将php运行于fpm模式;   &n…

    2017-06-06
  • Linux下各类颜色文件的意思

    Linux下各类颜色文件的意思   Linux系统对在终端下的各文件进行了颜色区分,了解各个颜色文件对应的意思对是学习Linux必须要掌握的。Linux文件颜色如下图: 1、白色:表示普通文件(-) 2、蓝色:表示目录(d) 3、绿色:表示可执行文件(-) 4、红色:表示压缩文件(-) 5、浅蓝色:链接文件(l) 6、黄色:表示设备文件(c) 7、…

    Linux干货 2016-10-18
  • N25-第四周

    复制/etc/ske1目录为/home/tuser1,要求/home/tuser及其内部文件的属组和其他用户均没有任何访问权限。 [root@localhost ~]# cp -a /etc/skel/ /home/tuser1[root@localhost ~]# ll -d /home/tuser1/drwxr-xr-x. 2 root root 59 …

    Linux干货 2016-12-25
  • 用户权限过滤练习(w4)

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

    系统运维 2016-11-20
  • ansible-yaml初级语法(hosts、remote_user、tasks)

    环境准备:     1、主控节点IP:172.16.16.9     2、两个被控节点:1)172.16.16.48   2)172.16.16.50     3、hosts配置如下:       &…

    Linux干货 2016-11-28
  • 系统用户基本信息

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 who | cut -d" " -f1 | sort -u who | cut -d" " -f1 | uniq 2、取出最后登录到当前系统的用户的相关信息。 who | tail -1 3、取出当前系统上被用户当作其默认she…

    Linux干货 2016-11-20

评论列表(1条)

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

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