Linux under the authority of the [set] RHEL8

1. How do you see and read rights information

View file properties

ls -l filename
-rw-r--r--. 1 root root 0 Dec 28 19:58 leesir

View Directory Properties

[root@workstation mnt]# ls -ld westosdir/
drwxr-xr-x. 2 leesir root 48 Dec 28 19:46 westosdir/

Here Insert Picture Description
Parameters directory for ld
To understand the file attributes of each field

  1. Types of
  2. file permission
  3. [A safe strengthening mechanisms under Linux] SELinux Context
  4. The number of hard linked files
  5. File owner
  6. File has set
  7. File size
  8. The file was last modified time
  9. file name

Directory for understanding the properties of each field

  1. Types of
  2. Directory Permissions
  3. [A safe strengthening mechanisms under Linux] SELinux Context
  4. Catalog number of subdirectories
  5. File owner
  6. File has set
  7. Directory metadata from files or subdirectories size
  8. The contents of the directory was last modified time
  9. Directory name

The type of file
- some common file system ##, normal commands, no file system function
D directory ##
S socket ## is assumed to be a shortcut
L link ##
C ## character device
B block device ##
Here Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description
block device
1 is not inserted into USB
Here Insert Picture Description2. insert USB
Here Insert Picture Description

2. The owner of the file and have set

Linux is a multi-user multi-tasking system, there are often many people use the same host at the same time to work, in order to consider each person's right to privacy and preferences of each person's work environment, the user classification

For user identity-based document
file owner (user)
Owned by group (group)
other people (other)

Change the file owner and the group that owns the method
file owner and have set only the super user root can modify

chown username file
chgrp group file name
chown -R username directory
chgrp -R group name directory
chown user name: Group name of the file
  • Create a user
    Here Insert Picture Description
  • / Mnt Create a directory of files and directories, and monitored for / mnt
    Here Insert Picture Description
    Here Insert Picture Description
    Here Insert Picture Description
  • The user owner / mnt / file1 changed chao
  • All groups / mnt / file2 changed lee
  • 将/mnt/file3的用户所有人改为chao,所有组改为lee【.可以改为:】
  • 将/mnt/test的用户所有人改为chao,所有组改为lee【.可以改为:】
    Here Insert Picture Description

3.文件权限的理解息

权限类型

-【权限关闭】 此位权限未开启
r【readable查看权限】 对于文件可查看文件中的内容;对于目录而言,可列出目录中的文件名称
w【writeable可写权限】 对于文件而言只是针对文件的内容,文件的属性是不可以更改;对于目录,增删文件,重命名
x【excutable执行权权限】 执行对于文件而言,是否可以发起文件里面的程序;执行对于目录而言,进入目录
  • 读权限
    文件而言
    开启,可以读取查看Here Insert Picture Description去掉r权限,再次读取,权限被拒绝
    Here Insert Picture DescriptionHere Insert Picture Description
    目录而言
    Here Insert Picture DescriptionHere Insert Picture Description
  • 写权限
    文件而言
    Here Insert Picture DescriptionHere Insert Picture Description
    目录而言
    Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description
  • 执行权限
    文件而言
    Here Insert Picture Description
    Here Insert Picture Description
    Here Insert Picture DescriptionHere Insert Picture Description
    目录而言
    Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description

4.文件权限设定方式

字符方式设定文件权限   • chmod [参数]... 权限模式[,权限模式]...目标...
数字方式设定文件权限 • chmod [参数]... 权限值...目标...
依照模板复制文件权限 • chmod [参数]... --reference=模板
  • 字符方式设定文件权限
    初始的样子
    Here Insert Picture Description
    具体的增减权限
    Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description对于所有的增删,提倡加a参数

  • 权限可以用一个八进制数字来表示

权限 二进制 八进制
000 0
–x 001 1
-w- 010 2
-wx 011 3
r– 100 4
r-x 101 5
rx- 110 6
rxw 111 7

Here Insert Picture DescriptionHere Insert Picture Description

  • 依照模板复制文件权限
    Here Insert Picture Description

5.系统预留权限阀值

对于权限预留阀值的理解

  • 资源存在意义在于共享,权限开放越大,共享效果越明显,但是安全性越差
  • 对于系统安全而言,开放权利越小,系统越安全
  • 在系统中开放应开放的权利,保留不安全的权利以确保系统功能性及安全性

权限预留阀值设定

umask ##系统中使用umask来预留权限
在shell中可以使用umask来查看并设定预留权限阀值
•umask预留阀值

永久改变权限阀值,shel中编写l配置文件/etc/bashrc,系统环境配置文件/etc/profile

  • 建立文件,目录查看权限
    Here Insert Picture Description
  • 自行设定,继续新建文件目录,发现变化
    Here Insert Picture Description
    Here Insert Picture Description
  • 永久设定,编辑文件【根据需求,编辑不同】
    Here Insert Picture Description
    Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description
    Here Insert Picture DescriptionHere Insert Picture Description
    Here Insert Picture DescriptionHere Insert Picture Description

6.特殊权限

对特殊权限的理解

SUID • 只针对于二进制可执行文件 , 使用拥有SUID权限的文件发其中记录的程序时以 文件拥有者的身份去执行
SGID • 针对二进制可执行文件 : 该命令发起的程序是以该命令所有组的身份去执行;• 针对目录 : 目录新建文件的所属组与该目录的所有组保持一致
STICKYID • 对于文件:表示文件即使没有被程序调用也会被加载到交换空间中,;• 对于目录:表示当目录上有 STICKYID 的权限时 , 所有用户在该目录下均可创建文件 , 但只有文件拥有者和 root 用户可以删除该目录下的文件

对特殊权限的设定

SUID • chmod u+s TAG;• chmod 4原文件属性 TAG
SGID • chmod g+s TAG;• chmod 2原文件属性 TAG
STICKYID • chmod o+t TAG;• chmod 1原文件属性 TAG
  • 建立公共目录。给其满权限
    Here Insert Picture DescriptionHere Insert Picture Description
  • 尝试删除文件
    Here Insert Picture Description
  • 加权限
    Here Insert Picture DescriptionHere Insert Picture Description
  • 监控cat命令执行
    Here Insert Picture Description
  • 用户chao执行命令
    Here Insert Picture Description
  • 用户lee执行命令
    Here Insert Picture Description
  • 加权限
    Here Insert Picture Description再次执行
    Here Insert Picture Description
  • 加命令执行所属组
    Here Insert Picture Description
    Here Insert Picture Description此时的cat被赋予超级用户权限,当普通用户使用此命令查看/etc/shadow也是ok得
    Here Insert Picture Description
    Here Insert Picture Description
  • 添加操作
    Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description

7.ACL权限列表

对于普通的权限只有三种身份,【owener,group,other】搭配三种权限【r,w,x】,但是并不能针对某一个使用者或者群组进行特定的权限设置,这时,就需要使用ACL(文件访问控制列表,Access Control List)机制

目前 ACL 几乎已经默认加入在所有常见的 Linux 文件系统的挂载参数中(ext2/ext3/ext4/xfs 等等 ), 但 rhel6.0以及之前的版本默认不支持 acl 的功能

有关facl的命令

设定权限列表

setfacl -m 设定权限
setfacl -x 删除指定用户
setfacl -b 关闭列表功能

查看权限列表

getfacl

  • 给用户chao赋予读写文件权限
    Here Insert Picture Description
    Here Insert Picture DescriptionHere Insert Picture Description
    Here Insert Picture Description
    lee用户不可以编辑
    Here Insert Picture Description
  • 设置权限
    Here Insert Picture Description
    Here Insert Picture Description
  • 删除
    Here Insert Picture Description
  • 关闭
    Here Insert Picture Description

facl列表权限匹配顺序

资源拥有者
特殊指定用户
权利开放多的组
权利开放少的组
其他用户

权限比较

  • 在/mnt目录之下新建一个用户所有人和组所有人都为pinyou的文件westos
    Here Insert Picture Description

  • 给westos文件添加特殊指定用户chao并赋予权限为0,再使用getfacl命令对于westos进行查看
    Here Insert Picture Description

  • 运用pinyou用户对于westos文件进行编辑,发现可以编辑成功,由此得出,资源拥有者所占权限的优先级高于特殊指定用户
    Here Insert Picture Description
    Here Insert Picture Description

  • 退出pinyou用户,再次查看westos文件权限
    Here Insert Picture Description

  • 建立用户组chao,赋予权限为0,再给用户所属组赋予rwx权限
    Here Insert Picture DescriptionHere Insert Picture Description

  • 尝试编辑文件,发现可以编辑成功,因此对于组的权限顺序来说,谁开放的权力越
    大,那么谁的顺序就靠前
    Here Insert Picture Description

facl的mask阀值

mask阀值是指定用户能够获取的最大有效权限
当设定过facl列表后用chmod缩减文件权限很可能会损坏mask
mask的设定 • setfacl –m m:权限值 TAG
  • 新建文件westos,并附加特殊指定用户chao,权限为rwx
    Here Insert Picture Description
  • chmod操作使得文件mask值改变,并且使得用户chao的权限减少为r
    Here Insert Picture Description
  • mask阈值设定
    Here Insert Picture Description

facl的default阀值
default权限特性

  • 只对目录设定
  • 只对目录中新出现的文件按或目录生效
  • 对目录本身不生效
  • 对目录中原有文件不生效
default权限设定方式   ##setfacl –m d:<u|g>:权限目录
  • 新建目录/westos,并且在该目录下新建文件file。特殊指定用户chao对于westos这个目录添加rwx权限
    Here Insert Picture Description

  • ls -l 查看westos目录,发现权限列表并未打开,并且对于目录中的file文件并未看到chao用户

  • 加上-R参数即可实现对该目录下所有文件或目录的权限列表操作
    Here Insert Picture Description

  • In westos directory and then create a file file1, getfacl not have permission to view and update the list. Visible, this set only for the current operation
    Here Insert Picture Description

  • Then you want the default permissions for the user's settings were emerging to take effect, you need to do the following
    Here Insert Picture Description

  • For the already existing file will not take effect
    Here Insert Picture Description

  • New file and view results
    Here Insert Picture Description

Published 15 original articles · won praise 4 · Views 386

Guess you like

Origin blog.csdn.net/weixin_43519951/article/details/103789079