当前位置:网站首页>14、用户、组和权限(14)
14、用户、组和权限(14)
2022-07-05 18:44:00 【51CTO】
文件系统的特殊权限
linux中有三种常见权限,还有三种特殊权限:suid,sgid,sticky
特殊权限suid
前提:进程有属主和属组,文件有属主和属组 (占据user的执行权限位, 数字法为4)
1、任何进程一个可执行程序文件能不能启动为进程,取决于发起者对程序文件是否具有执行权限
2、启动为进程之后,其进程属主为发起者,进程属组为发起者所属组
3、进程访问文件时的权限,取决于进程的发起者
a、进程的发起者,同文件的属主:则应用文件属主权限
b、进程的发起者,属于文件属组:则应用文件属组权限
c、应用文件其他权限
二进制的可执行文件上suid权限功能
任何一个可执行文件能不能启动为进程:取决于发起者对程序文件是否有执行权限
启动为进程之后,其进程的属主为原程序文件的属主
suid只对二进制可执行程序有效
suid设置在目录上无意义
suid 权限设定
chmod u+s file... chmod 6xxx file chmod u-s file ...


去掉s权限后,出现更改密码报错

重新赋予suid权限后可更新成功(结论:具有suid的权限;lgw用户调用passwd命令时,能临时获取到/usr/bin/passwd的属主的权限然后对shadows进行更新)

特殊权限sgid
二进制可执行文件上的sgid权限功能(占据group的执行权限位, 数字法为2)
任何一个可执行程序文件能不能驱动为进程:取决于发起者对程序文件是否有执行权限
启动为进程之后,其进程的属组为源程序文件的属主
sgid权限的设定 chmod g+s file... chmod 2xxx file chmod g-s file...
目录上sgid权限功能:默认情况下,用户创建文件时,其属组为此用户所属的主组,一但某目录被设定为sgid,则对此目录有写权限的用户在此目录中创建的文件所属的组为此目录的属组,通常用于创建一个协作目录。


特殊权限sticky
具有写权限的目录通常用户可以删除该目录中的任何文件,无论该文件的权限或拥有权限在马艳玲设置sticky位,只有文件的所有者或root可以删除该文件。(占据other的执行权限位, 数字法为1)
sticky权限设定 chmod o+t dir chmod 1xxx dir chmod o-t dir
other对/tmp目录具有写权限,理论上可以删除该目录下任何文件,但是加入sticky权限后,不能


设定文件的特殊属性
设定文件的特殊属性,可以访问root用户误操作或修改文件
不能删除,改名,更改 chattr +i

只能追加内容,不能删除,改名 chattr +a

列出特定属性 lsattr

访问控制列表(ACL)
acl:access control list 实现灵活的权限管理
除了文件所属主、所属组和other,可以对更多用户进行权限设置
centos7默认创建的xfs和ext4文件系统具有acl功能
tune2fs -o acl /dev/sdb1 mount -o acl /dev/sdb1 /mnt
acl生效顺序:所有者、自定义用户、所属组|自定义组,其他人
相关命令setfacl、getfacl
setfacl 设置acl权限
getfacl 查看设置的acl权限



mask权限
mask只影响所有者和other之外的人和组的最大权限
mask需要与用户的前行进行逻辑与运算后,才能变成有效的权限(effectice permission)
用户或组的设置必须存在于mask权限设定范围内才会生效
setfacl -m mask::rx file


other设置了acl权限为rwx,导致mask也为rmx


setfacl --set u::rw,u:wang:rw,g::r,o::- file1 --setfacl选项会把原有的acl项都删除,用新的替代,需要注意的是一定要宝行ugo的设置,不能像-m一样只是添加acl就可以
备份还原acl
主要文件操作命令为cp和mv都支持acl,只要cp命令需要加上-p参数,但是tar等常见的备份工具是不会保留目录和文件的acl信息
备份acl getfacl -R /tmp/dir > acl.txt
消除acl setfacl -R -b /tmp/dir
还原acl setfacl -R --set-file=acl.txt /tmp/dir
查看acl getfacl -R /tmp/dir

边栏推荐
- 在线协作产品哪家强?微软 Loop 、Notion、FlowUs
- Technology sharing | interface testing value and system
- 块编辑器如何选择?印象笔记 Verse、Notion、FlowUs
- 数学分析_笔记_第9章:曲线积分与曲面积分
- Web3.0时代来了,看天翼云存储资源盘活系统如何赋能新基建(下)
- Interprocess communication (IPC): shared memory
- Golang through pointer for Range implements the change of the value of the element in the slice
- ROS安装报错 sudo: rosdep:找不到命令
- CF: B. almost Ternary Matrix [symétrie + règles de recherche + Construction + I am Construction Waste]
- A cloud opens a new future of smart transportation
猜你喜欢

How to quickly advance automated testing? Listen to the personal feelings of the three bat test engineers

出海十年:新旧接力,黑马崛起

The worse the AI performance, the higher the bonus? Doctor of New York University offered a reward for the task of making the big model perform poorly

决策树与随机森林

android中常见的面试题,2022金九银十Android大厂面试题来袭

企业级数据安全,天翼云是这样理解的
![2022 latest intermediate and advanced Android interview questions, [principle + practice + Video + source code]](/img/c9/f4ab4578029cf043155a5811a64489.png)
2022 latest intermediate and advanced Android interview questions, [principle + practice + Video + source code]
![CF: B. almost Ternary Matrix [symétrie + règles de recherche + Construction + I am Construction Waste]](/img/5d/06229ff7cfa144dbcb60ae43d5c435.png)
CF: B. almost Ternary Matrix [symétrie + règles de recherche + Construction + I am Construction Waste]

Blue sky drawing bed Apple quick instructions

AI金榜题名时,MLPerf榜单的份量究竟有多重?
随机推荐
【Autosar 十四 启动流程详解】
技术分享 | 接口测试价值与体系
MySQL数据库索引教程(超详细)
泰山OFFICE技术讲座:由行的布局高度,谈绘制高度的高度溢出、高度缩水(全网首发)
Solutions contents have differences only in line separators
Case sharing | integrated construction of data operation and maintenance in the financial industry
Redhat7.4 configure Yum software warehouse (rhel7.4)
Find in MySQL_ in_ Detailed explanation of set() function usage
鱼和熊掌可以兼得!天翼云弹性裸金属一招鲜!
UDF implementation of Dameng database
Lombok @builder annotation
Reading notes of Clickhouse principle analysis and Application Practice (5)
5. 数据访问 - EntityFramework集成
2022最新Android面试笔试,一个安卓程序员的面试心得
如何快速进阶自动化测试?听听这3位BAT大厂测试工程师的切身感想....
Idea configuring NPM startup
数学分析_笔记_第9章:曲线积分与曲面积分
A2L file parsing based on CAN bus (3)
从外卖点单浅谈伪需求
Taishan Office Technology Lecture: from the layout height of the line, talk about the height overflow and height shrinkage of the drawing height (launched in the whole network)