首页 > 系统相关 >Linux文件目录权限与特殊权限

Linux文件目录权限与特殊权限

时间:2024-10-14 20:52:22浏览次数:3  
标签:txt 文件目录 big3 acl Linux rwx group 权限 root

18.文件与目录权限

文件访问者分类(朋友圈)

文件拥有者
文件所属组
文件的other


文件类型

d:目录文件
-:普通文件(文本,源代码,可执行程序,第三方动静态库)
l:软链接(类似Windows的快捷方式)
b:块设备文件(例如硬盘、光驱等)
p:管道文件
c:字符设备文件(例如屏幕等串口设备)
s:套接口文件


权限设置

[root@big3 demo1]# ll
总用量 8
-rw-r--r--. 1 root root 183 9月  30 08:33 1.txt
drwxr-xr-x.   2 root root    32 9月  30 08:34 demo1

drwxr-xr-x  10位,四组信息
第一组 : 1位, 文件类型
第二组 : 2-4位,文件所有者
第三组 : 5-7位,文件所属组
第四组 : 8-10位,其他用户


r w  x -> 4  2   1  ——》  可读  可写   可执行


权限    文件      目录
r       cat       ls
w       vim      rm mv
x        .sh      cd



权限修改

chmod

文件拥有者: u
文件所属组:g
文件的other:o


chmod  [ugoa]+-=[rwx]  文件/目录
chmod  数字  文件/目录





drwxr-xr-x. 2 root root   6 10月  9 09:22 1 更改目录权限,属主为rwx  属组rw 其他用户无权限
    [root@big3 demo1]# chmod 760 1
    [root@big3 demo1]# ll -d 1
    drwxrw----. 2 root root 6 10月  9 09:22 1
    [root@big3 demo1]# 
    [root@big3 demo1]# chmod g=rw,o=-  2
    [root@big3 demo1]# 
    [root@big3 demo1]# ll -d 2
    drwxrw----. 2 root root 6 10月  9 09:22 2
    [root@big3 demo1]# 


-rw-r--r--. 1 root root 183 9月  30 08:33 1.txt  更改文件权限,属主rwx 属组rx ,其他用户rwx

    [root@big3 demo1]# chmod u+x,g+x,o=rwx 1.txt 
    [root@big3 demo1]#  ll 1.txt 
    -rwxr-xrwx. 1 root root 183 9月  30 08:33 1.txt
    [root@big3 demo1]# 



chown

[root@big3 demo1]# ll        查看文件/目录权限
总用量 8
drwxrw----. 2 root root   6 10月  9 09:22 1
-rwxr-xrwx. 1 root root 183 9月  30 08:33 1.txt
drwxrw----. 2 root root   6 10月  9 09:22 2
-rw-r--r--. 1 root root 366 9月  30 08:34 2.txt
[root@big3 demo1]# 
[root@big3 demo1]# 
[root@big3 demo1]# 
[root@big3 demo1]# chown big1 1   更改属主
[root@big3 demo1]# 
[root@big3 demo1]# chown .admin 2   更改属组 
[root@big3 demo1]# 
[root@big3 demo1]# 
[root@big3 demo1]# chown big1.admin 1.txt   更改属主与属组
[root@big3 demo1]# 
[root@big3 demo1]# 
[root@big3 demo1]# ll
总用量 8
drwxrw----. 2 big1 root    6 10月  9 09:22 1
-rwxr-xrwx. 1 big1 admin 183 9月  30 08:33 1.txt
drwxrw----. 2 root admin   6 10月  9 09:22 2
-rw-r--r--. 1 root root  366 9月  30 08:34 2.txt


19.附加权限

粘滞位(T权限)

	共享文件夹 :bigWork     [root@big3 ~]# mkdir  /bigWork
	两个用户,分别创建文件
		big2:  big2.txt  
				echo "big4...">> big2.txt
		big4:  big4.txt      
				echo "big4...">> big4.txt
		[root@big3 bigWork]# ll
		总用量 8
		-rw-r--r--. 1 big2 big2 8 10月  9 14:50 big2.txt
		-rw-r--r--. 1 big4 big4 8 10月  9 14:49 big4.txt
		
		占用其他人(Other)的×位,显示为t或T,取决于其他人是否有x权限
		[root@big3 /]# ll -d bigWork/
		drwxr-xr-x. 2 root root 38 10月  9 14:50 bigWork/
		[root@big3 /]# chmod o+t  bigWork/ 
		[root@big3 /]# ll -d bigWork/
		drwxr-xr-t. 2 root root 38 10月  9 14:50 bigWork/
		
		[root@big3 /]# ll -d bigWork/
		drwxr-xrw-. 2 root root 38 10月  9 14:50 bigWork/
		[root@big3 /]# 
		[root@big3 /]# chmod o+t  bigWork/
		[root@big3 /]# ll -d bigWork/
		drwxr-xrwT. 2 root root 38 10月  9 14:50 bigWork/
		
		
		验证: 
			在设置了粘滞位的文件夹下,即使用户有写入(w)权限,也不能删除或改名其他用户文档
			


SGID权限

	对目录有效 :
		[root@big3 /]# mkdir /bigWork2
		[root@big3 /]# 
		[root@big3 /]# 
		[root@big3 /]# ll -d /bigWork2/
		drwxr-xr-x. 2 root root 6 10月  9 15:10 /bigWork2/
		[root@big3 /]# chown .admin /bigWork2/
		
	占用属组(Group)的x位,显示为s或S,取决于属组是否有x权限
		[root@big3 /]# ll -d /bigWork2/
		drwxr-xr-x. 2 root admin 19 10月  9 15:11 /bigWork2/
		[root@big3 /]# 
		[root@big3 /]# 
		[root@big3 /]# 
		[root@big3 /]# chmod g+s /bigWork2/
		[root@big3 /]# 
		[root@big3 /]# 
		[root@big3 /]# ll -d /bigWork2/
		drwxr-sr-x. 2 root admin 19 10月  9 15:11 /bigWork2/
	
	在一个具有SGID权限的目录下,新建的文档会自动继承此目录的属组身份
		[root@big3 /]# ll -d /bigWork2/
		drwxr-sr-x. 2 root admin 19 10月  9 15:11 /bigWork2/
		[root@big3 /]# cd bigWork2/
		[root@big3 bigWork2]# 
		[root@big3 bigWork2]# echo "Hello2" > 2.txt
		[root@big3 bigWork2]# 
		[root@big3 bigWork2]# 
		[root@big3 bigWork2]# ll
		总用量 8
		-rw-r--r--. 1 root root  6 10月  9 15:11 1.txt
		-rw-r--r--. 1 root admin 7 10月  9 15:15 2.txt
		[root@big3 bigWork2]# 


权限掩码

查看权限掩码:
		[root@big3 demo1]# umask
		0022
		
		目录算法 :777 - 022 = 755
		文件算法 :777 - 022 = 755 去掉X权限 644
	
		[root@big3 demo1]# ll
		总用量 0
		drwxr-xr-x. 2 root root 6 10月  9 15:49 1           755        777-022=755
		-rw-r--r--. 1 root root 0 10月  9 15:49 1.txt       644        777-022=755  - 减去x值   = 644
		
	修改权限压掩码:
		
		临时设置 : umask 值
		永久设置 :umask 的配置文件是 /etc/bashrc 。 最后一行的 umask 0077 改成需要修改的值,「重启系统」即可生效。


20.ACL访问策略

	能够对个别用户、个别组设置独立的权限
	
	[root@big3 /]# mkdir acl
	[root@big3 /]# 
	[root@big3 /]# ll -d acl/
	drwxr-xr-x. 2 root root 6 10月  9 17:42 acl/
	
	设置权限
		setfacl 选项 文件名 
		
		给指定用户设置权限
		setfacl -m u:big2:rwx acl
		
		查看权限
		getfacl acl/
		
		给指定用户取消权限
		setfacl -x u:big2 acl
		
		
		给指定组设置权限
		
		setfacl -m g:admin:rwx acl
		
		给指定组取消权限
		setfacl -x g:admin acl
		
		
		设置递归权限:(对已存在的子文件/目录生效)
			setfacl -m u:big2:rwx -R acl2
			
		删除所有acl权限
			setfacl -b acl2
			
		
	查看权限
		getfacl 文件名 



给指定用户设置/取消权限

[root@big3 /]# mkdir acl
[root@big3 /]# 
[root@big3 /]# ll -d acl/
drwxr-xr-x. 2 root root 6 10月  9 17:42 acl/
[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# getfacl acl/  查看权限
# file: acl/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

[root@big3 /]# setfacl -m u:big2:rwx acl  设置指定用户acl权限
[root@big3 /]# 
[root@big3 /]# getfacl acl/
# file: acl/
# owner: root
# group: root
user::rwx
user:big2:rwx
group::r-x
mask::rwx
other::r-x

[root@big3 /]# 
[root@big3 /]# setfacl -x u:big2 acl   取消指定用户权限
[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# getfacl acl/  查看权限
# file: acl/
# owner: root
# group: root
user::rwx
group::r-x
mask::r-x
other::r-x

[root@big3 /]# 


给指定组设置/取消权限

[root@big3 /]# getfacl /acl/
getfacl: Removing leading '/' from absolute path names
# file: acl/
# owner: root
# group: root
user::rwx
user:big2:rwx
group::r-x
mask::rwx
other::r-x

[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# setfacl -m g:admin:rwx acl       给指定组设置权限
[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# getfacl /acl/
getfacl: Removing leading '/' from absolute path names
# file: acl/
# owner: root
# group: root
user::rwx
user:big2:rwx
group::r-x
group:admin:rwx
mask::rwx
other::r-x

[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# setfacl -x g:admin acl  给指定组取消权限
[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# getfacl /acl/
getfacl: Removing leading '/' from absolute path names
# file: acl/
# owner: root
# group: root
user::rwx
user:big2:rwx
group::r-x
mask::rwx
other::r-x

[root@big3 /]# 


设置递归权限

(对已存在的子文件/目录生效)

[root@big3 /]# 
[root@big3 /]# setfacl -m u:big2:rwx -R acl2
[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# getfacl acl2/
# file: acl2/
# owner: root
# group: root
user::rwx
user:big2:rwx
group::r-x
mask::rwx
other::r-x

[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# cd acl2/
[root@big3 acl2]# 
[root@big3 acl2]# getfacl 1.txt 
# file: 1.txt
# owner: root
# group: root
user::rw-
user:big2:rwx
group::r--
mask::rwx
other::r--

[root@big3 acl2]# 
[root@big3 acl2]# ec
[root@big3 acl2]# 
[root@big3 acl2]# echo "sss"> 2.txt
[root@big3 acl2]# 
[root@big3 acl2]# 
[root@big3 acl2]# getfacl 2.txt 
# file: 2.txt
# owner: root
# group: root
user::rw-
group::r--
other::r--

[root@big3 acl2]# 
[root@big3 acl2]# setfacl -m g:admin:rwx -R acl2
setfacl: acl2: 没有那个文件或目录
[root@big3 acl2]# setfacl -m g:admin:rwx -R /acl2
[root@big3 acl2]# 
[root@big3 acl2]# 
[root@big3 acl2]# getfacl 2.txt 
# file: 2.txt
# owner: root
# group: root
user::rw-
group::r--
group:admin:rwx
mask::rwx
other::r--

[root@big3 acl2]# 
[root@big3 acl2]# 
[root@big3 acl2]# echo "sss"> 3.txt
[root@big3 acl2]# 
[root@big3 acl2]# 
[root@big3 acl2]# getfacl 3.txt 
# file: 3.txt
# owner: root
# group: root
user::rw-
group::r--
other::r--

[root@big3 acl2]# 


删除所有ACL权限

[root@big3 /]# getfacl  acl2/
# file: acl2/
# owner: root
# group: root
user::rwx
user:big2:rwx
group::r-x
group:admin:rwx
mask::rwx
other::r-x

[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# setfacl -b acl2/  删除所有ACL权限
[root@big3 /]# 
[root@big3 /]# 

[root@big3 /]# getfacl  acl2/
# file: acl2/
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

[root@big3 /]# 


设置/取消默认权限

setfacl -m d:u:用户名:权限 目录
	[root@big3 /]# setfacl -m d:u:big2:rx acl
setfacl -m d:g:组名:权限 目录
	[root@big3 /]# setfacl -m d:g:admin:rx acl
取消默认权限
 	setfacl -k acl   
注意点 : 只对新建子文件/目录有效



[root@big3 /]# cd acl
[root@big3 acl]# 
[root@big3 acl]# ll
总用量 0
[root@big3 acl]# echo "hello" > 1.txt
[root@big3 acl]# 
[root@big3 acl]# ll
总用量 4
-rw-r--r--. 1 root root 6 10月 10 08:24 1.txt
[root@big3 acl]# 
[root@big3 acl]# 
[root@big3 acl]# getfacl 1.txt 
# file: 1.txt
# owner: root
# group: root
user::rw-
group::r--
other::r--

[root@big3 acl]# 
[root@big3 acl]# 
[root@big3 acl]# cd ..
[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# setfacl -m d:u:big2:rx acl   设置默认权限
[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# getfacl acl
# file: acl
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx
default:user:big2:r-x
default:group::r-x
default:mask::r-x
default:other::r-x

[root@big3 /]# 
[root@big3 /]# 
[root@big3 /]# cd acl
[root@big3 acl]# 
[root@big3 acl]# 
[root@big3 acl]# getfacl 1.txt 
# file: 1.txt
# owner: root
# group: root
user::rw-
group::r--
other::r--

[root@big3 acl]# echo "hello" > 2.txt
[root@big3 acl]# 
[root@big3 acl]# 
[root@big3 acl]# getfacl 2.txt 
# file: 2.txt
# owner: root
# group: root
user::rw-
user:big2:r-x			#effective:r--
group::r-x			#effective:r--
mask::r--
other::r--

[root@big3 acl]# 

[root@big3 /]# setfacl -k acl    取消默认权限
[root@big3 /]# 
[root@big3 /]# getfacl acl
# file: acl
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

标签:txt,文件目录,big3,acl,Linux,rwx,group,权限,root
From: https://blog.csdn.net/weixin_42636042/article/details/142928455

相关文章

  • 2023 ThinkPad运行Linux选购思考记录
    2023ThinkPad运行Linux选购思考记录TieraRedHat高级混合云架构师/RHCALevel3​关注 17人赞同了该文章​展开目录 前言在当今这个数字化时代,笔记本电脑已成为我们日常生活和工作中不可或缺的工具。对于软件工程师和系......
  • HyperOS + Arch Linux dual boot on Xiaomi Pad 5 (nabu)
    HyperOS+ArchLinuxdualbootonXiaomiPad5(nabu)ResourcePreparationResourcepackages:ArchLinuxArmGnome.lni/UbuntuDesktop_noble.lni/...:LinuxRootfsImagePackages@timoxa0/Guide-Linux-NabuHyperOS1.1.5.0.VNXCNXM.BETA安卓15:HyperOSSystemP......
  • gaussdb 基础管理 数据库 表 用户 模式 权限 存储过程
    数据库database#创建数据库,指定字符集UTF8,缺省情况下新数据库将通过复制标准系统数据库template0来创建,且仅支持使用template0来创建。CREATEDATABASEdevdbENCODING'UTF8'template=template0;CREATEDATABASEtestdb;标识符的命名需要遵守如下规范:*标识符需要为......
  • 欧拉openEuler、Linux系统-(9) 文件操作命令集
    (请关注,本文将不断更新...,添加实用技巧和操作实例)在Linux系统中,熟练掌握各种文件操作命令是非常重要的。下面为大家详细介绍50个Linux系统中常用的文件操作命令。一、文件查看类命令1.lsls命令用于列出目录内容。用法:ls[选项][目录或文件]选项解释:-l:以长格式显示......
  • 代码江湖:快问快答 -【Linux】
    Linux筑基期1.什么是Linux操作系统?它与其他操作系统的区别是什么?2.如何查看当前Linux系统的版本信息?3.如何管理文件和目录?常用的文件操作命令有哪些?4.如何查看当前目录的路径?5.如何创建、编辑和查看文件?6.如何查看当前正在运行的进程?7.如何检查磁盘使用情况?......
  • 【Linux】解析信号的本质&相关函数及指令的介绍
    前言大家好吖,欢迎来到YY滴Linux系列,热烈欢迎!本章主要内容面向接触过C++的老铁主要内容含:欢迎订阅YY滴C++专栏!更多干货持续更新!以下是传送门!YY的《C++》专栏YY的《C++11》专栏YY的《Linux》专栏YY的《数据结构》专栏YY的《C语言基础》专栏YY的《初学者易错点》......
  • Linux 之 nano 编辑器
    使用git提交的时候,发生冲突或要记录相关信息时会弹出nano这个编辑器。nano[选项][[+行,列]文件名]...nano[必要参数][选择参数][文件]命令行白的部分是组合键,后面的则是该组合键的功能。指数符号(^)代表的是键盘的[ctrl]按键,(M)表示Alt键。[Ctrl]-G:取得在线帮助(hel......
  • 十、Linux 之定时任务调度
    1、crond任务调度crontab进行定时任务的设置1.1概述任务调度:是指系统在某个时间执行的特定的命令或程序。任务调度分类:1.系统工作:有些重要的工作必须周而复始地执行。如病毒扫描等个别用户工作:个别用户可能希望执行某些程序,比如对mysql数据库的备份。示意图......
  • 华为云 linux centos8 安装tendis
    一、下载下载地址:http://tendis.cn/#/点击右上角的Download点击tendisplus-2.7.0-rocksdb-v8.5.3.tgz,由于下载速度非常慢,改用wget方式下载解决云服务器中访问github速度慢的问题:linux中在/etc/hosts中添加如下内容:20.205.243.166github.com输入下载命令:wgethttps:/......
  • Linux常用命令(每日两更)
     一、Linux基础命令1、bc数字计算器作用:用于数字计算以及进制转换#安装bc工具[root@192~]#yum-yinstallbc>/dev/null;echo-e"\a"​#bc用于数字计算[root@192~]#echo"1+1"|bc2​#bc用于进制转换obase表示输出的进制,ibase表示输入的进制[root@19......