Linux 文档权限解析

1 篇文章 0 订阅
1 篇文章 0 订阅

Linux文件权限困扰已久,这两天重新认识了一下。本文仅做为自己Linux中使用的点滴记录。

1.Linux文件基本权限及系统中的标识;

[root@QT-Server home]#ls -al  #查询当前目录文件信息
drwxr-xr-x+  8 root   root        4096 5月   5 17:42 .
dr-xr-xr-x. 18 root   root        4096 5月   7 10:01 ..
-rw-r--r--.  1 root   root      126672 10月 30 2019 excelFileSize
drwxrwxr-x+ 16 root   root        4096 5月   5 14:38 file           

 

2.Linux基本权限

文件基本操作权限,在Linux中有读、写、执行三种,又有区分用户、组、其他等三种区分。读、写、执行对应的字母分别是r(read),w(write),x(execute),通常按照rwx顺序排列。下图是文件权限的说明:

2.1Linux文件操作基础命令:

1、ls查看文件属性:ls -al

2、touch 新建文件: touch <文件名>

3、mkdir新建目录: mkdir <文件夹名称>

4、cp 拷贝文件:cp <file1> <file2>   拷贝file1并更名为file2 

5、mv更改文件名或者转移文件: mv <file1> <file2> 将file1更名为file2 ,或者 将 file1 移动到 file2(file1和file2都可以是路径,类型需要相同)

6、chwon 改变文件所有者:chown <user> <file name>

7、chgrp 改变文件所属组: chgrp <group> <file name>

8、chmod 改变文件权限:  chmod <right No. eg:644> <filen ame>

9、du 显示文件占用空间.

10、df 查看磁盘使用空间

3.Linux文件权限扩展:ACL

ACL权限主要用在基本权限无法满足需求的情况,比如某公司制造部,制作的某个文档(比如这里是名为SMT的目录),所有者和所属组都可以访问文件,但是有一个其他部门的人,现在因为项目需求需要访问此文件,这个时候基本的文件权限就无法满足现在的需求,这个时候就到了ACL出场的时候了。ACL作为文件基本权限的一个扩展,其操作命令主要有两个:getfaclsetfacl。

getfacl :查看文件的ACL表

setfacl 设置文件的ACL表

主要参数:-m 修改或添加ACL权限;-R 递归目录,主要用户对文件夹的操作;-x 取消ACL权限;-b 清除ACL权限;-d 设置默认权限;  -u设置用户权限;  -g设置组用户权限

3.1 Linux文件权限系统中使用的命令

1、查看SMT文件夹的ACL表:

getfacl <文件名或者目录名>

[root@QT-Server shell]#getfacl SMT
# file: SMT
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

给SMT目录添加部门以外的人员(用户smbody或者组somebody)访问权限:

[root@QT-Server shell]#setfacl -m u:somebody:r-x SMT

2、添加ACL条目(-m)

[root@QT-Server shell]#setfacl -m u:somebody:r-x SMT    #添加授权
[root@QT-Server shell]#getfacl SMT  #查看ACL表
# file: SMT
# owner: root
# group: root
user::rwx
user:jingle:r-x
user:somebody:r-x
group::r-x
mask::r-x
other::r-x

3、取消ACL条目(-x)

[root@QT-Server shell]#setfacl -x u:somebody SMT  #取消用户somebody的授权
[root@QT-Server shell]#getfacl SMT
# file: SMT
# owner: root
# group: root
user::rwx
user:jingle:r-x
group::r-x
mask::r-x
other::r-x

4、清除ACL条目(-b)

[root@QT-Server shell]#setfacl -b SMT   #删除所有ACL条目
[root@QT-Server shell]#getfacl SMT
# file: SMT
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

[root@QT-Server shell]#ls -al | grep SMT
drwxr-xr-x. 2 root root 4096 5月   7 18:44 SMT  
[root@QT-Server shell]#ls -al
总用量 16
drwxr-xr-x. 3 root root 4096 5月   7 18:44 .
drwxr-xr-x+ 9 root root 4096 5月   7 18:47 ..
drwxr-xr-x. 2 root root 4096 5月   7 18:44 SMT
[root@QT-Server shell]#setfacl -m u:jingle:rwx SMT
[root@QT-Server shell]#ls -al
总用量 20
drwxr-xr-x. 3 root root 4096 5月   7 18:44 .
drwxr-xr-x+ 9 root root 4096 5月   7 18:47 ..
drwxrwxr-x+ 2 root root 4096 5月   7 18:44 SMT     #添加ACL条目后,"."变成了"+"

5、设置默认权限:用户在目录中新建的文件夹的默认权限。

[root@SHELL shell]# getfacl SMT
# file: SMT
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

[root@SHELL shell]# setfacl -d -R -m g:TEST:r-x SMT       #-d 添加默认属性  -R 递归向下传递
[root@SHELL shell]# getfacl SMT
# file: SMT
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx
default:group::r-x
default:group:TEST:r-x
default:mask::r-x
default:other::r-x

设置默认权限以后,用户在目录下新建的内容都都会默认添加上default:开头的权限属性。
 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值