文件目录常规权限设置_2

本文详细介绍了Linux系统中关于文件和目录的权限管理,包括使用chmod命令进行权限设置,如增加、删除用户执行权限,以及如何通过chown改变文件的属主和属组。同时,还探讨了文件访问控制列表(facl)的应用,如何为单个用户或用户组设置特定权限以及如何删除这些权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

常规权限:
r read 读取 4
w write 写入 2
x execute 执行 1

文件 :
r 查看文件内容(cat/more/less/head/tail/grep)
w 编辑文件内容(vim)
x shell/python脚本

目录 :
r 查看目录下的文件(ls /tmp)
w 修改目录下的文件(新建、删除、mv)
x 切换目录 (cd)

查看文件权限

查看目录权限

[root@192 ~]# ls  -ld /etc/
drwxr-xr-x. 140 root root 8192 May  3 14:09 /etc/

设置文件目录权限

1)chmod

chmod {augo}{±=}{rwx} 文件名称

 a  all    所有
 u  user   属主用户权限
 g  group  属组
 o  other  其他

#chmod a+x /tmp/1.txt
#chmod u-x,o+r /tmp/2.txt

[root@192 huge]# chmod a+x 1.txt   
[root@192 huge]# chmod u-x,o+r 2.txt 
[root@192 home]# chmod g=rw /home/huge/3.txt 

# chmod nnn 文件名称

[root@192 home]# chmod 600 /home/huge/4.txt
  1. 修改文件的属主、属组

chown 用户名称、用户组名称 文件名称

[root@192 home]# chown user1.caiwu /home/huge/1.txt >>> 更改用户的属主及属组1.text

[root@192 home]# chown user2 /home/huge/2.txt >>> 更改用户的属主

[root@192 huge]# chgrp caiwu 2.txt >>> 更改用户的属组

3)facl ----- 文件访问控制列表

设置权限

针对单个用户

# setfacl -m u : 用户名: 权限 文件名称
[root@192 huge]# setfacl -m u:user4:r 3.txt >>> 把3.txt文件的读权限赋给user4

[root@192 huge]# getfacl 3.txt >>> 查看.txt文件的ACL权限

针对单个用户删除权限:

[root@192 huge]# setfacl -x u:user4 3.txt >>> 把user4的acl 权限删掉

针对单个用户组

setfacl -m g : 用户组名:权限 文件名称

针对单个用户组删除权限

setfacl -x g:用户组名称 文件名称

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值