码迷,mamicode.com
首页 > 其他好文 > 详细

权限管理-ACL

时间:2017-09-29 01:38:43      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:boot   方法   es2017   管理   chm   其他   strong   tmp   lin   

                                权限管理-ACL

                                                        作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

一.ACL权限简介与开启
1.ACL权限简介
  比如在根下有一个目录(”/yinzhengjie“),这个目录的所有者和所属组都是root,查看其权限是770,这意味着,只有root用户或是在root组里面的用户才能操作这个文件。如果有一个人不是root又不是root这个组里面的用户,但是就是有一个需求想要看”/yinzhengjie“这个目录下的内容该如何呢?
Linux在这一点的处理上和windows有点像,它的操作方法就是给这个用户加权限即可。让其有访问这个目录的权限即可,这个时候我们就得学习一下ACL啦。
 
2.查看分区ACL权限是否开启
要想利用ACL这个权限,还得看分区是否支持ACL权限哟~
 1 [root@yinzhengjie ~]# df -h
 2 Filesystem Size Used Avail Use% Mounted on
 3 /dev/sda2 18G 2.8G 14G 17% /
 4 tmpfs 491M 224K 491M 1% /dev/shm
 5 /dev/sda1 283M 28M 240M 11% /boot
 6 [root@yinzhengjie ~]#
 7 [root@yinzhengjie ~]#
 8 [root@yinzhengjie ~]#
 9 [root@yinzhengjie ~]# dumpe2fs -h /dev/sda2 | grep "Default mount options"
10 dumpe2fs 1.41.12 (17-May-2010)
11 Default mount options: user_xattr acl
12 [root@yinzhengjie ~]#   
                      技术分享
温馨提示:如果上图中没有ACL权限的话,也不要慌,还是有解决方案的。
a>.临时开启分区ACL权限:(重新挂载根分区,并挂载加入acl权限。)
[root@yinzhengjie ~]# mount -o remount,acl /
[root@yinzhengjie ~]#
b>.编辑"/etc/fstab"配置文件(它是开机自动挂载的文件。)
  修改这个配置文件一定要小心,一旦修改错误,系统就会崩溃,你将无法启动你的操作系统哟,因为你挂载根就会挂载失败啊,当然,还是可以通过救援模式进行修复的。
                      技术分享
二.查看与设定ACL权限
1.查看ACL命令(getfacl)
                       技术分享
2.设定ACL权限的命令(setfacl)
我们先看看常用的几个参数的解释:
                      技术分享
 1 [root@yinzhengjie ~]# mkdir /yinzhengjie/
 2 [root@yinzhengjie ~]# useradd canglaoshi
 3 [root@yinzhengjie ~]# useradd jichimingbu
 4 [root@yinzhengjie ~]# groupadd AVgroup
 5 [root@yinzhengjie ~]# gpasswd -a canglaoshi AVgroup
 6 Adding user canglaoshi to group AVgroup
 7 [root@yinzhengjie ~]# gpasswd -a jichimingbu AVgroup
 8 Adding user jichimingbu to group AVgroup
 9 [root@yinzhengjie ~]# 
10 [root@yinzhengjie ~]# tail -1 /etc/group
11 AVgroup:x:504:canglaoshi,jichimingbu
12 [root@yinzhengjie ~]# 
13 [root@yinzhengjie ~]# chown root:AVgroup /yinzhengjie/
14 [root@yinzhengjie ~]# chmod 770 /yinzhengjie/
15 [root@yinzhengjie ~]# ll -d /yinzhengjie/
16 drwxrwx---. 4 root AVgroup 4096 9月  28 12:56 /yinzhengjie/
17 [root@yinzhengjie ~]# 
18 [root@yinzhengjie ~]# 
19 [root@yinzhengjie ~]# useradd yangmi
20 [root@yinzhengjie ~]# echo "123456" | passwd --stdin yangmi
21 更改用户 yangmi 的密码 。
22 passwd: 所有的身份验证令牌已经成功更新。
23 [root@yinzhengjie ~]# 
24 [root@yinzhengjie ~]# setfacl -m u:yangmi:rx /yinzhengjie/
25 [root@yinzhengjie ~]# 
26 [root@yinzhengjie ~]# getfacl /yinzhengjie/
27 getfacl: Removing leading / from absolute path names
28 # file: yinzhengjie/
29 # owner: root
30 # group: AVgroup
31 user::rwx
32 user:yangmi:r-x
33 group::rwx
34 mask::rwx
35 other::---
36 
37 [root@yinzhengjie ~]# 
38 [root@yinzhengjie ~]# ll -d /yinzhengjie/
39 drwxrwx---+ 4 root AVgroup 4096 9月  28 12:56 /yinzhengjie/
40 [root@yinzhengjie ~]# 
41 [root@yinzhengjie ~]# su yangmi
42 [yangmi@yinzhengjie root]$ 
43 [yangmi@yinzhengjie root]$ cd /yinzhengjie/
44 [yangmi@yinzhengjie yinzhengjie]$ ls
45 golang  postfix
46 [yangmi@yinzhengjie yinzhengjie]$ touch {1..5}.txt
47 touch: 无法创建"1.txt": 权限不够
48 touch: 无法创建"2.txt": 权限不够
49 touch: 无法创建"3.txt": 权限不够
50 touch: 无法创建"4.txt": 权限不够
51 touch: 无法创建"5.txt": 权限不够
52 [yangmi@yinzhengjie yinzhengjie]$ 

                                  技术分享

  创建之后,可以进行以下测试,发现之后读取权限确实没有写的权限呢
                           技术分享
  如果你想要对一个组设置ACL权限,操作和用户类似:
                            技术分享
三.最大有效权限与删除ACL权限
1.最大有限权限mask
  mask是用来指定最大有效权限的。如果我给用户赋予了ACL权限,是需要和mask的权限“相与”才能得到用户的真正权限。
                              技术分享

  

  mask权限一般适用于对一个文件提前做出最大权限的规划,这样即使我用acl给其他用户分配权限过高,但是只要和mask进行相与操作,最终用户得到的权限仍然在我们的控制范围之内呢。
                            技术分享
2.删除ACL权限
 1 [root@yinzhengjie ~]# setfacl -x g:movie /yinzhengjie/
 2 [root@yinzhengjie ~]# getfacl /yinzhengjie/
 3 getfacl: Removing leading / from absolute path names
 4 # file: yinzhengjie/
 5 # owner: root
 6 # group: AVgroup
 7 user::rwx
 8 user:yangmi:r-x
 9 group::rwx
10 mask::rwx
11 other::---
12  
13 [root@yinzhengjie ~]#
14 [root@yinzhengjie ~]# setfacl -b /yinzhengjie/
15 [root@yinzhengjie ~]# getfacl /yinzhengjie/
16 getfacl: Removing leading / from absolute path names
17 # file: yinzhengjie/
18 # owner: root
19 # group: AVgroup
20 user::rwx
21 group::rwx
22 other::---
23  
24 [root@yinzhengjie ~]# ll -d /yinzhengjie/
25 drwxrwx---. 4 root AVgroup 4096 9月 28 12:56 /yinzhengjie/
26 [root@yinzhengjie ~]#

                                技术分享

四.默认ACL权限和递归ACL权限
1.递归ACL权限
  递归是父目录在设定ACL权限时,所有的子文件和子目录也会拥有相同的ACL权限。
 1 [root@yinzhengjie ~]# mkdir /yinzhengjie
 2 [root@yinzhengjie ~]# touch /yinzhengjie/{1..5}.txt
 3 [root@yinzhengjie ~]# ll /yinzhengjie/
 4 总用量 0
 5 -rw-r--r--. 1 root root 0 9月 28 23:29 1.txt
 6 -rw-r--r--. 1 root root 0 9月 28 23:29 2.txt
 7 -rw-r--r--. 1 root root 0 9月 28 23:29 3.txt
 8 -rw-r--r--. 1 root root 0 9月 28 23:29 4.txt
 9 -rw-r--r--. 1 root root 0 9月 28 23:29 5.txt
10 [root@yinzhengjie ~]#
11 [root@yinzhengjie ~]# setfacl -m u:yangmi:rx -R /yinzhengjie/
12 [root@yinzhengjie ~]#
13 [root@yinzhengjie ~]# ll /yinzhengjie/
14 总用量 20
15 -rw-r-xr--+ 1 root root 0 9月 28 23:29 1.txt
16 -rw-r-xr--+ 1 root root 0 9月 28 23:29 2.txt
17 -rw-r-xr--+ 1 root root 0 9月 28 23:29 3.txt
18 -rw-r-xr--+ 1 root root 0 9月 28 23:29 4.txt
19 -rw-r-xr--+ 1 root root 0 9月 28 23:29 5.txt
20 [root@yinzhengjie ~]#
21 [root@yinzhengjie ~]# getfacl /yinzhengjie/1.txt
22 getfacl: Removing leading / from absolute path names
23 # file: yinzhengjie/1.txt
24 # owner: root
25 # group: root
26 user::rw-
27 user:yangmi:r-x
28 group::r--
29 mask::r-x
30 other::r--
31  
32 [root@yinzhengjie ~]#

                                    技术分享

 

权限管理-ACL

标签:boot   方法   es2017   管理   chm   其他   strong   tmp   lin   

原文地址:http://www.cnblogs.com/yinzhengjie/p/7609177.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!