ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux-文件权限

2021-03-26 16:30:45  阅读:268  来源: 互联网

标签:文件 权限 sticky 文件夹 andy Linux txt


Linux-文件权限

一. 基本权限UGO

1.1 改变属主chown

chown andy.tony file 改变属主和属组
chown andy file 改变属主
chown .tony file 改变属组

1.2 改变属组chgrp

chgrp andy file

1.3 用符号方式改变文件权限

chmod a+w,g=-,o-w 1.txt
a: 属主权限
g:属组权限
o:其他人权限

1.4 用数字方式改变文件权限

chmod 777 1.txt

1.5 rwx权限对文件和文件夹的意义

						文件						文件夹
r						读文件						查看文件夹中的文件
w						写文件						向文件夹添加删除文件
x						执行文件					进入文件夹

二. 基本权限ACL

ACL可以对某个人、某个组单独设置rwx的基本权限

2.1 getfacl 查看文件的acl权限

有个加号代表该文件有acl权限设置
在这里插入图片描述

[root@localhost ~]# getfacl /tmp/1.txt 
getfacl: Removing leading '/' from absolute path names
# file: tmp/1.txt
# owner: root
# group: root
user::rw-
user:andy:rwx
group::r--
group:tony:---
mask::rwx
other::--x

2.2 setfacl设置文件的acl权限

参数:
-m: 设置acl权限
-x: 删除acl权限
-b: 清空acl权限

[root@localhost ~]# setfacl -m u:andy:rwx -m g:tony:- -m o:x /tmp/1.txt 

2.3 将一个文件的acl权限复制给另一个文件

getfacl file1 |setfacl --set-file=- file2

2.4 ACL高级特征

2.4.1 mask

  1. mask控制除属主和other外的所有用户和组的权限;
  2. 设置mask权限后,除属主和other外的所有用户和组的最高权限是mask的权限;
  3. 设置mask权限后,任何设置acl权限的操作都将取消mask权限限制
[root@localhost ~]# setfacl -m mask:- /tmp/1.txt 
[root@localhost ~]# getfacl /tmp/1.txt 
getfacl: Removing leading '/' from absolute path names
# file: tmp/1.txt
# owner: root
# group: root
user::rw-
user:andy:rwx			#effective:---
group::r--			#effective:---
group:tony:rwx			#effective:---
mask::---
other::--x

2.4.2 default

想要为一个文件夹下所有子文件夹和文件设置acl权限,要加参数-d;
加了参数-d设置的acl权限没有应用到本文件夹,只能应用到子文件夹和文件;

setfacl -m d:u:andy:wx /tmp/111

三. 高级权限suid,sgid,sticky

suid 4
sgid 2
sticky 1

  1. 用字符设置特殊权限:
    chmod u+s file
    chmod g+s dir
    chmod o+t dir
  2. 用数字
    chmod 4777 file
    chmod

3.1 suid

只能给二进制可执行文件赋suid权限;不能给文件夹赋;
不论哪个用户使用这个有suid权限的二进制程序去操作文件时,这个二进制程序都是用他的属主的身份去操作文件的;

例子:

  1. 用户andy没有文件1.txt的任何权限
    在这里插入图片描述
    在这里插入图片描述

  2. 赋予cat这个二进制文件suid权限
    在这里插入图片描述

  3. 然后再用andy去cat 1.txt。可以了
    在这里插入图片描述

  4. 赋予rm这个二进制文件suid权限

  5. andy可以删除1.txt了
    在这里插入图片描述

3.2 guid

给文件夹赋予guid权限后,在这个文件夹里面新创建的文件或文件夹的属组都继承该文件夹的

3.3 sticky

只能对文件夹设置sticky权限;
有sticky权限的文件夹中的文件只能被root、文件夹的属主、文件的属主删除;

  1. 创建一个文件夹,给other rwx权限
    [root@localhost ~]# mkdir /test_sticky
    [root@localhost ~]# chmod o+rwx /test_sticky/

  2. 用用户andy在该文件夹里面创建一个andy.txt文件
    在这里插入图片描述

  3. 用用户tony在该文件夹里面创建一个tony.txt文件
    在这里插入图片描述

  4. andy可以删除andy.txt和tony.txt
    在这里插入图片描述

  5. 给目录test_sticky赋予sticky权限
    [root@localhost ~]# chmod o+t /test_sticky/

  6. andy只能删除andy.txt不能删除tony.txt
    [andy@localhost test_sticky]$ rm -rf /test_sticky/{andy.txt,tony.txt}
    rm: cannot remove ‘/test_sticky/tony.txt’: Operation not permitted

标签:文件,权限,sticky,文件夹,andy,Linux,txt
来源: https://blog.csdn.net/qq_33808440/article/details/115183789

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有