扩展权限ACL的应用
发布日期:2022-02-22 18:04:26 浏览次数:4 分类:技术文章

本文共 4502 字,大约阅读时间需要 15 分钟。

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} -->

文件扩展权限限制 ACL

用户大家对 Linux/Unix UGO 权限管理方式一定不陌生. 为了实现一些比较复杂的权限管理,往往不得不创建很多的组,并加以详细的记录和区分这是一件很麻烦的事。为了能使某一个用户对某一文件指定一个权限,比如对某一个特定的文件,用户A 可以读取,用户B 所在的组可以修改,惟独用户B 不可以……。于是就有了IEEE POSIX 1003.1e 这个ACL 的标准。ACL 的出现专门解决了这个问题。下面我们来探讨下ACL 在实际生活中的应用。

扩展acl 的一些基本语法

getfacl  -d     文件的默认权限

setfacl  -m     设置扩展权限

              |u  针对用户设置扩展权限

              |g   针对组置扩展权限

              |d     设置默认权限

              |m   设定统一收回么个选项

       -k    移除默认acl 条目

       -R     权限递归

       -x      取消特定权限

setfacl   -    取消宽展权限

首先我们要在linux 加载硬盘acl 功能的支持

    #vim  /etc/fstab

   /rich    ext3    defaults,acl    1 2

default 后面加入acl 然后重新挂载硬盘

#mount o remount | /home

查看验证下是否添加成功

#mount (看/etc/fstab 中添加的内容是否正常出现)新文件apple

#touch  apple

#getfacl  apple

#su  -  aaa

$vim  /root/apple

这里我们发现permission   denied 无写权限

$su  -  root

#setfacl  u:aaa rwx

$vim   /root/apple

这里我们就可以正常写入了,我们下面添加一个组

$su -  root

#getfacl  g:nasasha:rw

#su  -  nasasha

$vim  /root/apple

 

 

 

 

 

 

 

#  touch file1

#  ls -l file1

-rw-r--r-- 1 root root     7 Dec 11 00:28 file1

 

查看文件缺省的ACL ,这时这个文件除了通常的UGO 的权限之外,并没有ACL

 

#  getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

group::r--

other::r-

 

下面添加几个用户和组,一会我将使用ACL 赋予他们不同的权限:

 

#  groupadd testg1

#  useradd testu1

#  useradd testu2

#  usermod -G testg1 testu1

 

切换到用户testu1

 

# su testu1

$ echo "testu1" >> file1

bash: file1: Permission denied

 

失败了。因为file1 并不允许除了root 以外的用户写。我们现在就通过修改file1ACL 赋予testu1 足够的权限:

 

# setfacl -m u:testu1:rw file1

# su testu1

$ echo "testu1" >> file1

$ cat file1

testu1

 

修改成功了,用户testu1 可以对file1 做读写操作了。我们来看一下file1ACL

 

$ getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

user:testu1:rw-

group::r--

mask::rw-

other::r-

 

我们ls 看一下:

 

# ls -l file1

-rw-rw-r--+ 1 root root     7 Dec 11 00:28 file1

 

如果仔细看的话,我们会发现权限末尾有个“+ ”号 ,这个说明file1 设置了ACL , 接下来我们修改一下testu1 的权限,同时给testg1 这个组以读的权限:

 

# setfacl -m u:testu1:rwx,g:testg1:r file1

# getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

user:testu1:rwx

group::r--

group:testg1:r--

mask::rwx

other::r-

 

 

# setfacl -m mask::r file1]# getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

user:testu1:rwx                  #effective:r--

group::r--

group:testg1:r--

mask::r--

other::r--

 

# ls -l file1

-rw-r--r--+ 1 root root 7 Dec 11 00:28 file1

 

删除已有的ACL

 

# setfacl -x g:testg1 file1

# getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

user:testu1:rwx

group::r--

mask::rwx

other::r--

 

我们看到testg1 的权限已经被去掉了。如果需要去掉所有的ACL 可以用-b 选项。所有的ACL 项都会被去掉。

 

# setfacl -b file1

# getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

group::r--

other::r--

 

 

# setfacl --set u::rw,u:testu1:rw,g::r,o::- file1

# getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

user:testu1:rw-

group::r--

mask::rw-

other::---

 

 

]# setfacl -d --set g:testg1:rwx dir1

]# getfacl dir1

# file: dir1

# owner: root

# group: root

user::rwx

group::r-x

other::r-x

default:user::rwx

default:group::r-x

default:group:testg1:rwx

default:mask::rwx

default:other::r-x

 

建立一个文件试试:

 

# touch dir1/file1

# getfacl dir1/file1

# file: dir1/file1

# owner: root

# group: root

user::rw-

group::r-x                      #effective:r--

group:testg1:rwx                #effective:rw-

mask::rw-

other::r--

 

 

# getfacl -R dir1 > dir1.acl

# ls -l dir1.acl

total 16

-rw-r--r--  1 root root   310 Dec 12 21:10 dir1.acl

 

我们用-b 选项删除所有的ACL 数据,来模拟从备份中回复的文件和目录:

 

 

# setfacl --restore dir1.acl

# getfacl -R dir1

# file: dir1

# owner: root

# group: root

user::rwx

group::r-x

other::r-x

default:user::rwx

default:group::r-x

default:group:testg1:rwx

default:mask::rwx

default:other::r-x

 

# file: dir1/file1

# owner: root

# group: root

user::rw-

group::r-x                       #effective:r--

group:testg1:rwx                #effective:rw-

mask::rw-

other::r--

 

 

 

转载地址:https://blog.csdn.net/FengzhizizhiLINUX/article/details/5297055 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:本地yum安装
下一篇:Mybatis(拦截器实现)通用mapper及全ORM实现(一)

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年03月30日 02时15分11秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

[Java爬虫] 使用 Xpath + HtmlUnit 爬取网页基本信息 2019-04-27
[人工智能] 使用百度 API 读取身份证照片的文字 2019-04-27
在SpringBoot中使用【阿里云OSS对象存储】存取图片 2019-04-27
[Java爬虫] 使用 HtmlUnit + Xpath 模拟点击、动态获取信息 2019-04-27
使用 SpringBoot 之 JPA 整合 Redis 实现缓存 2019-04-27
SpringBoot 结合 JSR303 对前端数据进行校验 2019-04-27
SpringBoot 整合 MongoDB 之 MongoTemplate 实现 CRUD、分页接口 2019-04-27
[增删改查] SpringBoot 整合 Solr 之 SolrClient 实现 CRUD、分页接口、高亮显示 2019-04-27
[Python爬虫] 模拟浏览器、代理ip、开启日志、超时处理、异常处理、登录、下载图片 2019-04-27
在 SpringBoot 中使用 @EnableAsync、@Async 轻松实现异步任务 2019-04-27
《学习 Go 语言》学习心得 2019-04-27
[汇编语言] 带有颜色的字符串显示(hello world 级别程序) 2019-04-27
[增删改查] Python 之使用 Django + LayUI 做后台管理 2019-04-27
Docker 镜像容器 之 导出导入、上传镜像到 DockerHub 上、Nexus私库 的引入 2019-04-27
centos7 下将 Django2.0 项目部署到 阿里云 上(uwsgi3 +Nginx ) 2021-06-30
前后端分离 SpringBoot + SpringSecurity 权限解决方案 2021-06-30
前后端分离 SpringBoot + SpringSecurity + JWT + RBAC 实现用户无状态请求验证 2021-06-30
[Python爬虫] 使用 Beautiful Soup 4 快速爬取所需的网页信息 2021-06-30
在 Centos7 下使用 Docker 快速搭建 Hadoop 集群 2021-06-30
Python web 框架 Flask 蓝图的正确使用姿势 2021-06-30