您的位置:首页 > 运维架构 > Linux

linux高级权限(ACL与sudo)

2015-11-10 20:19 513 查看
ACL是Access Control List的缩写,主要的目的是在提供传统的owner,group,others的read,write,execute权限之外的局部权限设定。ACL可以针对单个用户,单个文件或目录来进行r,w,x的权限设定,特别适用于需要特殊权限的使用情况。简单地来说,ACL就是可以设置特定用户或用户组对于一个文件/目录的操作权限。首先要查看系统是否支持ACL,具体的操作步骤如图:

有图可以看出是支持ACL的。要是不支持可以通过命令mount -o remount,acl /dev/sda1来重新挂载。1.setfacl设置文件权限setfacl参数如下:-m :设置后续的acl参数-x :删除后续的acl参数-b :删除所有的ACL设定参数-R :递归设置acl参数-d :设置预设的acl参数(只对目录有效,在该目录新建的文件也会使用此ACL默认值)-k :删除预设的ACL参数eg:setfacl -m u:user1:rw my.cnf-sample.txt2.getfacl查看文件权限eg:getfacl my.cnf-sample.txt3.删除文件权限eg:setfacl -x u:user1 my.cnf-sample.txt4.清空文件权限eg:setfacl -b my.cnf-sample.txt上边都是针对单个文件的,同理也可以针对文件夹来进行设置。如果要在某个文件夹下新增的文件(夹)继承属性的话可以用如下的命令:setfacl -m d:u:user1:rw -R my.cnf-sample.txt来实现。
sudo” 是Unix/Linux平台上的一个非常有用的工具,允许为非根用户赋予一些合理的“权利”,让他们执行一些只有根用户或特许用户才能完成的任务,从而减少根用户的登陆次数和管理时间同时也提高了系统安全性。sudo的目的:为非根用户授予根用户的权限;

配置文件:/etc/sudoers

visudo命令编辑修改/etc/sudoers配置文件

1、一般用户赋权设置:[root@localhost ~]# visudo
……前面省略
69 ## Syntax:
70 ##
71 ## user MACHINE=COMMANDS
72 ##
73 ## The COMMANDS section may have other options added to it.
74 ##
75 ## Allow root to run any commands anywhere
76 root ALL=(ALL) ALL77 test ALL=(root) /usr/sbin/useradd //新增加用户行
……后面省略
第一个字段:root为能使用sudo命令的用户;
第二个字段:第一个ALL为允许使用sudo的主机,第二个括号里的ALL为使用sudo后以什么身份(目的用户身份)来执行命令;
第三个字:ALL为以sudo命令允许执行的命令;
上列解释: test ALL=(root) /usr/sbin/useradd
表示允许test用户从任何主机登录,以root的身份执行/usr/sbin/useradd命令。
[root@server ~]# su - redhat
[redhat@server ~]$ sudo /usr/sbin/useradd test
//命令需要输入完整的路径
口令: //这里输入用户redhat自己的密码
[redhat@server ~]$ cat /etc/passwd |tail -5
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
redhat:x:500:500::/home/redhat:/bin/bash
test:x:501:501::/home/test:/bin/bash //新增加的用户

2、sudo配置深入:
1)多个用户的设置(非同一群组用户):
对于不同需求的用户:可以按照上面的方法依次增加多行,每行对应一个用户。
对于相同需求的多个用户
User_Alias UUU=user1,user2…… 定义用户别名;

[root@localhost ~]# visudo
……前面省略
16 ## User Aliases
17 ## These aren't often necessary, as you can use regular groups
18 ## (ie, from files, LDAP, NIS, etc) in this file - just use %groupname
19 ## rather than USERALIAS
20 # [b]User_Alias ADMINS = jsmith, mikem //[b]这个就是一个实例行,按照这个写自己的
[/b]
21 User_Alisa sudouser=user1,user2,user3,user4 //第一一个别名suduouser
……后面省略
69 ## Syntax:
70 ##
71 ## user MACHINE=COMMANDS
72 ##
73 ## The COMMANDS section may have other options added to it.
74 ##
75 ## Allow root to run any commands anywhere
76 root ALL=(ALL) ALL77 sudouser ALL=(root) /usr/sbin/useradd ////命令行书写格式,用户列用别名
……后面省略[/b]
对于多个命令的设置:
Cmnd_Alias CCC=command1,command2…… 定义命令别名;

[root@localhost ~]# visudo
……前面省略
23 ## Command Aliases
24 ## These are groups of related commands...
25
26 ## Networking
27 Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dh client, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig, /sbin/mii-tool [b]//
多个命令定义一个命令别名;
……后面省略
69 ## Syntax:
70 ##
71 ## user MACHINE=COMMANDS
72 ##
73 ## The COMMANDS section may have other options added to it.
74 ##
75 ## Allow root to run any commands anywhere
76 root ALL=(ALL) ALL77 sudouser ALL=(root) NETWORKING //命令行书写格式,命令列用别名
……后面省略[/b]

对于多主机的设置和多登陆角色的设置:
修改 Host_Alias HHH=host1,host2…… 定义主机别名;
修改后对应的命令行主机列位置也是用别名
Runas_Alias RRR=role1,role2…… 定义runas别名,指定的是“目的用户”,即sudo 允许转换至的用户;
[b] 建立相关别明后,相关命令行相应的列也是用我们定义的别名。

2)多个用户的设置(同一群组用户): [/b]
[root@localhost ~]# visudo
……前面省略
81
82## Allows people in group wheel to run all commands
83# [b]%wheel ALL=(ALL) ALL //
用户列%+群组名
……后面省略[/b]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息