权限作业

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

相关推荐

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

    1、源码编译安装LNMP架构环境; 安装开发包组 yum groupinstall "Development Tools" "Server Platform Development" -y yum install -y …

    Linux干货 2017-01-03
  • MySQL半同步配置

    先配置主从服务器,过程见另一篇博库 就是先搭一个主从服务器,然后 1、先在主节点上安装半同步复制的主节点专用插件 MariaDB [(none)]> SHOW PLUGINS;这条命令可以查看有哪些插件可以用 2、从节点也一样先装插件 从节点上先停止线程 STOP SLAVE; 主节点上 从节点上 START SLAVE; 这里需要手动的停止一下线程,…

    Linux干货 2016-11-21
  • 初识Linux

    在这篇文章中你讲看到如下内容: 1.       计算机的组成及功能; 2.       Linux发行版之间的区别和联系; 3.       Linux发行版的基础目录及功用规定…

    Linux干货 2016-12-01
  • class-6 积累应用

    1、三种权限rwx对文件和目录的不同意义     ## 读写执行对于文件的意义         r:针对于文本文件         w:可修改内容,但不能删除文件本身,需要x权限配合  &n…

    Linux干货 2016-08-05
  • rpm与yum

    rpm包及yum 包查询 rpm -q –query  搭配别的选项可用来包查询 -a -f -p rpmfile:针对尚未安装的程序包文件做查询操作   -p 选项参数为文件名(一定要指定路径) 例子: rpm -qpl /media/Packages/zsh-4.3.11-4.el6.centos.2.x86_64.rpm…

    Linux干货 2016-08-24
  • 马哥教育网络班20期+第5周课程练习

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行; grep "^[[:space:]]\+.*" /boot/grub/grub.conf   2、显示/etc/rc.d/rc.sysinit文件中以#开头,后面跟至少一个空白字符,而后又有至少一个非空白字符的行; grep&nb…

    Linux干货 2016-07-12