权限作业

  • 三种权限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

相关推荐

  • 用户及组权限结合grep过滤示例

    grep与正则表达式,用户及组权限管理

    Linux干货 2018-02-06
  • MySQL主从复制:半同步、异步

            MySQL主从复制:半同步、异步 前言 如何对MySQL进行扩展? MySQL Replication WorkFlow MySQL主从复制模式 实战演练 MySQL异步复制实现 MySQL半同步复制实现 实验中的思考 总结 mysql 前言 本篇我们介绍MySQ…

    Linux干货 2016-04-28
  • Linux文本处理工具及组管理

    1、列出当前系统上所有已经登录的用户名,注意:同一个用户登录多次,只显示一次即可 [root@centos ~]# who | cut -d' ' -f1 | sort -u     gentoo &…

    Linux干货 2016-10-09
  • Linux的哲学思想

    Linux的哲学思想 linux有个哲学的思想是一切皆文件 其中linux硬件设备也是通过文件来表示的 物理终端 物理终端指的是显示器等硬件终端设备,文件存在于 /dev/console 这个路径下 虚拟终端 虚拟终端指的是在linux命令行连接的终端,文件存在于 /dev/tty# [1,6] 这个路径下 串行终端 指的是使用计算机串行端口连接的终端设备,…

    Linux干货 2018-02-23
  • DNS高级应用之子域授权&区域转发

    一、环境准备:    1、准备三台测试服务器,划分如下:    主DNS服务器:eth0:192.168.10.203;负责mylinux.com域解析;确保可以正常解析      子域DNS服务器:eth0:192.168.10.120; 负责子域ops.mylinux.com解析; &…

    Linux干货 2015-06-01
  • 软件包管理(rpm篇)

    软件包管理(rpm篇)静态和动态链接    链接主要作用是把各个模块之间相互引用的部分处理好,使得各个模块之间能够正确地衔接,分为静态链接和动态链接    静态链接        把程序对应的依赖库复制一份到包&nbsp…

    Linux干货 2017-04-24