权限作业

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

    对文件来说:
    r:可获取文件的数据;
    w:可修改文件的数据;(但不能删除文件)
    x:可将此文件运行为进程;(针对二进制文件或脚本)
    (一般而言,文件默认情况下都不该有执行权限)
    对目录来说:
    r:可以使用ls获取其下的所有文件列表;但不能访问文件,不能cd进目录,不能查看文件的详细信息(元数据)
    w:可修改此目录下的文件列表;即创建或删除文件;需要配合x权限来操作
    x:可cd至此目录中,且可使用ls-l来获取所有文件的详细属性信息;可以访问目录中的文件	
  • umask和acl mask 的区别和联系

    umask命令用来设置限制新建文件权限的掩码
    acl musk 也可以用来限制权限,这是他们的联系
      区别:      
     umask与mask的区别感觉就是mask是给权限设置了一个界限,除了root和文件所有者和other外的其他用户或者组不能超过他设置的权限界限,
     只能低于或者等于。而umask是给定一个模式,只要用户创建目录或者文件,其所得到的权限是一定的。
  • 三种特殊权限的应用场景和作用

    当一个用户执行一个二进制文件权限不够时可以用SUID权限。SUID只能运用在二进制可执行文件上,当用户执行该执行文件时,会临时拥有该执行文件所有者的权限
      当多个用户属于同一项目组,或者需要对同一目录的文件或者子目录都可以自由操作时,可以用SGID权限。SGID可以应用在目录或可执行文件上。当SGID应用在文件上时,用户访问该文件时执行的是文件所属组的操作权限。
      当SGID应用在目录上时,该目录中所有新建立的文件或子目录的属组都会是该目录的属组
      Sticky权限只能应用在目录,当目录拥有Sticky所有在该目录中的文件或子目录无论是什么权限只有文件或子目录所有者和root用户能删除。
  • 设置user1,使之新建文件权限为rw——-

    [user1@localhost ~]$ nano /home/user1/.bashrc          
      # .bashrc
      
      # Source global definitions
      if [ -f /etc/bashrc ]; then
              . /etc/bashrc
      fi  
      # Uncomment the following line if you don't like systemctl's auto-paging feature:
      # export SYSTEMD_PAGER=
      
      # User specific aliases and functions
      
      umask 066
    
    
      [user1@localhost ~]$ 
      [user1@localhost ~]$ umask  0066
      [user1@localhost ~]$ touch f2
      [user1@localhost ~]$ ll f2
      -rw------- 1 user1 user1 0 Aug  4 20:26 f2
  • 设置/testdir/f1的权限,使user1用户不可以读写执行,g1组可以读写 /testdir/dir的权限,使新建文件自动具有acl权限:user1:rw,g1:— 备份/testdir目录中所有文件的ACL,清除/testdir的所有ACL权限,并利用备份还原

    [root@localhost ~]# mkdir testdir
      [root@localhost ~]# touch testdir/f1
      [root@localhost ~]# setfacl -m u:user1:0 testdir/f1
      [root@localhost ~]# mkdir testdir/dir
      [root@localhost ~]# groupadd g1
      groupadd: group 'g1' already exists
      [root@localhost ~]# setfacl -m g:g1:rw tsetdir/dir
      setfacl: tsetdir/dir: No such file or directory
      [root@localhost ~]# setfacl -m g:g1:rw testdir/dir
      [root@localhost ~]# setfacl -Rm d:u:user1:rw testdir
      [root@localhost ~]# setfacl -Rm d:g:g1:0 testdir
      [root@localhost ~]# touch testdir/f2
      [root@localhost ~]# getfacl testdir/f2
      # file: testdir/f2
      # owner: root
      # group: root
      user::rw-
      user:user1:rw-  group::r-x			#effective:r--
      group:g1:---  mask::rw-
      other::r--
      
      [root@localhost ~]# getfacl testdir/f1
      # file: testdir/f1
      # owner: root
      # group: root
      user::rw-
      user:user1:---  group::r--
      mask::r--
      other::r--
      
      [root@localhost ~]# getfacl testdir/dir
      # file: testdir/dir
      # owner: root
      # group: root
      user::rwx
      group::r-x
      group:g1:rw-  mask::rwx
      other::r-x
      default:user::rwx
      default:user:user1:rw-  default:group::r-x
      default:group:g1:---  default:mask::rwx
      default:other::r-x
      
      [root@localhost ~]# getfacl testdir
      # file: testdir
      # owner: root
      # group: root
      user::rwx
      group::r-x
      other::r-x
      default:user::rwx
      default:user:user1:rw-  default:group::r-x
      default:group:g1:---  default:mask::rwx
      default:other::r-x
      [root@localhost ~]# getfacl -R testdir > file.acl
      [root@localhost ~]# cat file.acl
      # file: testdir
      # owner: root
      # group: root
      user::rwx
      group::r-x
      other::r-x
      default:user::rwx
      default:user:user1:rw-  default:group::r-x
      default:group:g1:---  default:mask::rwx
      default:other::r-x
      
      # file: testdir/f1
      # owner: root
      # group: root
      user::rw-
      user:user1:---  group::r--
      mask::r--
      other::r--
      
      # file: testdir/dir
      # owner: root
      # group: root
      user::rwx
      group::r-x
      group:g1:rw-  mask::rwx
      other::r-x
      default:user::rwx
      default:user:user1:rw-  default:group::r-x
      default:group:g1:---  default:mask::rwx
      default:other::r-x
      
      # file: testdir/f2
      # owner: root
      # group: root
      user::rw-
      user:user1:rw-  group::r-x	#effective:r--
      group:g1:---  mask::rw-
      other::r--
      
      [root@localhost ~]# setfacl -R -b testdir
      [root@localhost ~]# getfacl testdir
      # file: testdir
      # owner: root
      # group: root
      user::rwx
      group::r-x
      other::r-x
      
      [root@localhost ~]# setfacl -R --set-file=file.acl testdir
      [root@localhost ~]# getfacl -R testdir
      # file: testdir
      # owner: root
      # group: root
      user::rw-
      user:user1:rw-  group::r-x			#effective:r--
      group:g1:---  mask::rw-
      other::r--
      default:user::rwx
      default:user:user1:rw-  default:group::r-x
      default:group:g1:---  default:mask::rwx
      default:other::r-x
      
      # file: testdir/f1
      # owner: root
      # group: root
      user::rw-
      user:user1:rw-  group::r-x			#effective:r--
      group:g1:---  mask::rw-
      other::r--
      
      # file: testdir/dir
      # owner: root
      # group: root
      user::rw-
      user:user1:rw-  group::r-x			#effective:r--
      group:g1:---  mask::rw-
      other::r--
      default:user::rwx
      default:user:user1:rw-  default:group::r-x
      default:group:g1:---  default:mask::rwx
      default:other::r-x
      
      # file: testdir/f2
      # owner: root
      # group: root
      user::rw-
      user:user1:rw-  group::r-x			#effective:r--
      group:g1:---  mask::rw-
      other::r--

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

赞 (0)
dxkbokedxkboke
上一篇 2016-08-05 10:18
下一篇 2016-08-05 10:18

相关推荐

  • N25-第三周作业

    第三周作业 1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 ~]#who | cut -d' ' -f 1 | sort | uniq 2、取出最后登录到当前系统的用户的相关信息。 ~]#who |tail -1 3、取出当前系统上被用户当作其默认shell的最多的那个shell。 ~]#cat…

    Linux干货 2016-12-18
  • httpd

      httpd http服务器程序:   httpd (apache) nginx lighttpd httpd的特性:   高度模块化: core + modules DSO:dynamic shared object(模块的动态加载) MPM:Multipath processing Modules (多路处理模块) &nb…

    Linux干货 2017-06-04
  • 管道及重定向

    管道及重定向 1、重定向 在Linux中有时我们在命令的执行过程中,不想将执行结果显示到屏幕上,或者将其结果输出到其他位置 这时就需要重定向来解决这个问题了 首先了解一下Linux中的3种I/O设备: 0:标准输入 1:标准输出 2:标准错误输出 输出重定向:> >> 输入重定向: < << >:将标准输出重定向到文…

    Linux干货 2017-07-28
  • 2016/10/14作业

    操作类: 1、设置自己的终端提示符,要求终端登陆时:     a> 需要带颜色      b> 需要显示当前执行到了第几条命令      c> 显示当前登录终端,主机名和当前时间 首先我们要了解一个环境…

    Linux干货 2016-10-19
  • nginx及I/O介绍原理

    上课笔记

    2018-03-12
  • Nginx

        Nginx(发音同engine x)是一个 Web服务器,也可以用作反向代理,负载平衡器和 HTTP缓存。Nginx 可以部署在网络上使用 FastCGI,脚本,SCGI 处理程序,WSGI 应用服务器或 Phusion 乘客模块的动态 HTTP 内容,并可作为软件负载均衡器。Nginx 使…

    Linux干货 2017-08-29