table of Contents
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/
Parameters directory for ld
To understand the file attributes of each field
- Types of
- file permission
- [A safe strengthening mechanisms under Linux] SELinux Context
- The number of hard linked files
- File owner
- File has set
- File size
- The file was last modified time
- file name
Directory for understanding the properties of each field
- Types of
- Directory Permissions
- [A safe strengthening mechanisms under Linux] SELinux Context
- Catalog number of subdirectories
- File owner
- File has set
- Directory metadata from files or subdirectories size
- The contents of the directory was last modified time
- 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 ##
block device
1 is not inserted into USB
2. insert USB
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
- / Mnt Create a directory of files and directories, and monitored for / mnt
- The user owner / mnt / file1 changed chao
- All groups / mnt / file2 changed lee
- 将/mnt/file3的用户所有人改为chao,所有组改为lee【.可以改为:】
- 将/mnt/test的用户所有人改为chao,所有组改为lee【.可以改为:】
3.文件权限的理解息
权限类型
-【权限关闭】 | 此位权限未开启 |
---|---|
r【readable查看权限】 | 对于文件可查看文件中的内容;对于目录而言,可列出目录中的文件名称 |
w【writeable可写权限】 | 对于文件而言只是针对文件的内容,文件的属性是不可以更改;对于目录,增删文件,重命名 |
x【excutable执行权权限】 | 执行对于文件而言,是否可以发起文件里面的程序;执行对于目录而言,进入目录 |
- 读权限
文件而言
开启,可以读取查看去掉r权限,再次读取,权限被拒绝
目录而言
- 写权限
文件而言
目录而言
- 执行权限
文件而言
目录而言
4.文件权限设定方式
字符方式设定文件权限 • chmod [参数]... 权限模式[,权限模式]...目标...
数字方式设定文件权限 • chmod [参数]... 权限值...目标...
依照模板复制文件权限 • chmod [参数]... --reference=模板
-
字符方式设定文件权限
初始的样子
具体的增减权限
对于所有的增删,提倡加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 |
- 依照模板复制文件权限
5.系统预留权限阀值
对于权限预留阀值的理解
- 资源存在意义在于共享,权限开放越大,共享效果越明显,但是安全性越差
- 对于系统安全而言,开放权利越小,系统越安全
- 在系统中开放应开放的权利,保留不安全的权利以确保系统功能性及安全性
权限预留阀值设定
umask ##系统中使用umask来预留权限
在shell中可以使用umask来查看并设定预留权限阀值
•umask预留阀值
永久改变权限阀值,shel中编写l配置文件/etc/bashrc,系统环境配置文件/etc/profile
- 建立文件,目录查看权限
- 自行设定,继续新建文件目录,发现变化
- 永久设定,编辑文件【根据需求,编辑不同】
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 |
- 建立公共目录。给其满权限
- 尝试删除文件
- 加权限
- 监控cat命令执行
- 用户chao执行命令
- 用户lee执行命令
- 加权限
再次执行
- 加命令执行所属组
此时的cat被赋予超级用户权限,当普通用户使用此命令查看/etc/shadow也是ok得
- 添加操作
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赋予读写文件权限
lee用户不可以编辑
- 设置权限
- 删除
- 关闭
facl列表权限匹配顺序
资源拥有者 |
---|
特殊指定用户 |
权利开放多的组 |
权利开放少的组 |
其他用户 |
权限比较
-
在/mnt目录之下新建一个用户所有人和组所有人都为pinyou的文件westos
-
给westos文件添加特殊指定用户chao并赋予权限为0,再使用getfacl命令对于westos进行查看
-
运用pinyou用户对于westos文件进行编辑,发现可以编辑成功,由此得出,资源拥有者所占权限的优先级高于特殊指定用户
-
退出pinyou用户,再次查看westos文件权限
-
建立用户组chao,赋予权限为0,再给用户所属组赋予rwx权限
-
尝试编辑文件,发现可以编辑成功,因此对于组的权限顺序来说,谁开放的权力越
大,那么谁的顺序就靠前
facl的mask阀值
mask阀值是指定用户能够获取的最大有效权限 |
---|
当设定过facl列表后用chmod缩减文件权限很可能会损坏mask |
mask的设定 • setfacl –m m:权限值 TAG |
- 新建文件westos,并附加特殊指定用户chao,权限为rwx
- chmod操作使得文件mask值改变,并且使得用户chao的权限减少为r
- mask阈值设定
facl的default阀值
default权限特性
- 只对目录设定
- 只对目录中新出现的文件按或目录生效
- 对目录本身不生效
- 对目录中原有文件不生效
default权限设定方式 ##setfacl –m d:<u|g>:权限目录
-
新建目录/westos,并且在该目录下新建文件file。特殊指定用户chao对于westos这个目录添加rwx权限
-
ls -l 查看westos目录,发现权限列表并未打开,并且对于目录中的file文件并未看到chao用户
-
加上-R参数即可实现对该目录下所有文件或目录的权限列表操作
-
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
-
Then you want the default permissions for the user's settings were emerging to take effect, you need to do the following
-
For the already existing file will not take effect
-
New file and view results