A rights management

A, ACL permissions

If we only want a certain user to file or have permission, you can use the acl rights.

1, to see whether to open acl
[root@localhost ~]# dumpe2fs -h /dev/mapper/VolGroup-lv_root # /设备文件名,可以用mount查看。

Default mount options:    user_xattr acl#默认开启

#如果没有开启,手工开启分区的 ACL 权限
[root@localhost ~]# mount -o remount,acl / # 重新挂载根分区,并挂载加入 acl 权限

也可以通过修改/etc/fstab 文件,永久开启 ACL 权限

[root@localhost ~]# vi /etc/fstab 
/dev/mapper/VolGroup-lv_root /                       ext4    defaults,acl        1 1   # 加入 acl 

[root@localhost ~]# mount -o remount /     #重新挂载 / 分区
2, ACL basic commands
getfacl  文件名  查询文件的 ACL 权限 

[root@localhost ~]# getfacl /root
getfacl: Removing leading '/' from absolute path names
# file: root
# owner: root
# group: root
user::r-x
group::r-x
other::---

setfacl  选项  文件名  设定 ACL 权限
-m       设定 ACL 权限   
-b       删除 ACL 权限   
-R       只能对目录使用,递归赋予权限
-x:用户  删除单个用户的 ACL 权限

用法:
    setfacl  -m  u:用户名:权限   文件名  
    setfacl  -m  g:组名:权限   文件名 
[love2@localhost ~]$ ls /root
ls: 无法打开目录/root: 权限不够,此时我们可以对love2用户授予acl权限,使其能够对/root目录由访问权限。
[root@localhost ~]# setfacl -m u:love2:rx /root

注意:如果给目录赋予 acl 权限,两条命令都要输入,递归与默认的区别:   
setfacl -m u:love2:rx -R /root        只对已经存在的文件生效   
setfacl -m d:u:love2:rx -R /root/   只对以后新建的文件生效
3, the maximum effective rights mask
[root@localhost /]# setfacl -m m:rw  123.txt   # 设定 mask 权限为 r - w ,给123.txt文件设定最大权限为 r-w
[root@localhost ~]# getfacl 123.txt 
# file: 123.txt
# owner: root
# group: root
user::rw-
group::r--
mask::rw-
other::---
4, delete permissions acl
[root@localhost ~]# setfacl -x u:love2 /root/ # 删除指定用户和用户组的 ACL 权限 
[root@localhost ~]# setfacl -b /root # 会删除文件的所有的 ACL 权限

Two, sudo authorization

When the average user does not have permission to perform certain commands, you can use the sudo command gives part of administrator privileges.

1 root identity:

visudo given normal user command, the command execution and use the same vim

#Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
#用户名  目标主机= (可使用的身份) 授权命令(绝对路径) 
#Allows people in group wheel to run all commands
%wheel        ALL=(ALL)       ALL 
% 组名 被管理主机的地址 = (可使用的身份) 授权命令(绝对路径) 

example

1)授权用户 love2 可以重启服务器,则visudo添加如下行: 
[root@localhost ~]# visudo / vim /etc/sudoers
love2  ALL=(root)   /sbin/shutdown –r now 
[user1@localhost ~]$ sudo -l #查看可用的授权  

2)授权love2用户可以添加其他普通用户  
love2  ALL=/usr/sbin/useradd    #赋予 love2 添加用户权限.命令必须写入绝对路径 
love2  ALL=/usr/bin/passwd       
love2 ALL=/usr/bin/passwd [A-Za-z0-9]*,  !/usr/bin/passwd "",  !/usr/bin/passwd root   #赋予改密码权限,取消对 root 的密码修改
 
切换love2 身份    
sudo  /usr/sbin/useradd  love3  

Guess you like

Origin www.cnblogs.com/hjnzs/p/11965516.html