Linux系统管理_ACL访问控制-Redhat Enterprise 5

简介:

Linux系统管理_ACL访问控制_Redhat Enterprise 5


概述:访问控制,当文件或目录的权限不能在完全满足访问控制的实现时,可以使用acl进行设置访问权限。

即,对一个文件或者目录设置个别(特殊)用户对其有操作的权限


ACL访问控制的作用:

1,对于程序来说,可以赋予某个用户对这个程序的acl访问控制,例如,单独为某个普通用户设置为对shutdown 命令有所有的权限。

2,对目录来说,具有acl访问控制权限,那么所有用户在此目录下建立的文档或目录将会自动继承该目录acl控制策略


注:

1,在安装系统的时候创建的磁盘分区具有acl的特性;(补充里面详解)

[root@localhost~]# tune2fs -l /dev/sda2 | grep acl

Default mount options:   user_xattr acl

2,系统安装后所划分的磁盘分区默认不支持acl

3,可使用tune2fs-l  /dev/sdb1 | grep acl来查看一个文件系统是否支持acl

如果支持,则会有相应的输出信息,如上面的1所示的输出内容,如果不支持,则

表示不支持。

4,tune2fs -l命令只能查看安装系统时候所划分的文件系统是否支持acl,新建立的分区查看的时候只能用mount | grep 设备名(补充里面详解)





一:查看ACL控制策略

[root@localhost~]# df -h /     //首先查看根目录的文件系统

文件系统容量已用 可用 已用% 挂载点

/dev/sda2             19G  2.3G   16G 13% /

[root@localhost~]# tune2fs -l /dev/sda2 | grep acl  //查看/dev/sda2文件

                          //系统是否支持acl,可以看到输出结果中包含acl

Default mount options:   user_xattr acl

[root@localhost~]# getfacl Desktop/   //查看Desktop的acl控制策略

# file: Desktop

# owner: root

# group: root

user::rwx

group::r-x

other::r-x


[root@localhost~]#


注:默认情况下,未设置任何额外的acl策略。


二:定义ACL访问控制策略:setfacl

setfacl命令:

-格式:setfacl [选项] u:用户名:权限文件

      setfacl [选项] g:组名:权限文件

选项有:

-m :定义一条acl策略

-x :清除指定的acl策略(补充里面详解)

-b :清除所有已设置的acl策略

-R :递归设置acl策略

-d :为目录设默认acl权限(子文档自动继承)


示例1:setfacl的-m选项

为/root设置acl策略,使user1具有rx权限

[root@localhost~]# getfacl /root/     //首先查看一下/root目录的acl权限

getfacl: Removing leading '/' from absolute path names

# file: root

# owner: root

# group: root

user::rwx

group::r-x

other::---


//可以看到,除了基本的权限之外,没有acl访问控制列表

[root@localhost~]# ll -d /root/

drwxr-x--- 17 root root 4096 02-18 21:43 /root/

[root@localhost~]# su - user1      //切换到user1用户,并尝试进入/root目录

[user1@localhost~]$ cd /root/

-bash: cd: /root/: 权限不够     //user1用户没有权限进入/root目录

[user1@localhost~]$ exit

logout

[root@localhost~]# setfacl -m user:user1:r-x /root  

//给/root目录添加一条acl策略,使用户user1对/root目录具有r和x的权限。

[root@localhost/]# ll -d /root/

drwxr-x---+ 17 rootroot 4096 02-18 21:43 /root/

//可以看到,设置了acl策略的目录的权限位将会有一个“+”标示!!!文件也一样

[root@localhost~]# getfacl /root/        //查看/root目录的acl权限

getfacl: Removing leading '/' from absolute path names

# file: root

# owner: root

# group: root

user::rwx

user:user1:r-x     //可以看到,这里有一条acl策略,user1具有r和x权限

group::r-x

mask::r-x

other::---


[root@localhost~]# su - user1     //再次切换到user1用户

[user1@localhost~]$ cd /root/       //可以看到,user1可以成功进入/root目录

[user1@localhostroot]$ ls

anaconda-ks.cfg  Desktop file1.txt  file2.txt  install.log install.log.syslog

[user1@localhostroot]$ pwd

/root

[user1@localhostroot]$


示例2:setfacl的-d选项

创建一个目录/acltest,并设置权限为所有人具有所有权限

设置/acltest目录的acl权限为user1具有rwx

分别使用root用户和user2用户建立目录test1、test2以及文档file1.txt、file2.txt

查看test1、test2、file1.txt、file2.txt的acl策略。


具体操作:

[root@localhost~]# mkdir /acltest        //创建/acltest目录

[root@localhost~]# chmod  777/acltest/      //设置权限为777

[root@localhost~]# getfacl /acltest/     //查看acl策略,这时没设置

getfacl: Removing leading '/' from absolute path names

# file: acltest

# owner: root

# group: root

user::rwx

group::r-x

other::r-x


[root@localhost~]# setfacl -dm u:user1:rwx /acltest/

//为/acltest目录设置acl策略为用户user1具有rwx权限

//注:设置用户时候user可以缩写为u

[root@localhost~]# getfacl /acltest/

getfacl: Removing leading '/' from absolute path names

# file: acltest

# owner: root

# group: root

user::rwx

group::rwx

other::rwx

default:user::rwx

default:user:user1:rwx      //默认的acl策略

default:group::r-x

default:mask::rwx

default:other::r-x


[root@localhost~]# mkdir /acltest/test1  //root用户建立test1目录

[root@localhost~]# touch /acltest/file1.txt   //root用户的文件file1.txt

[root@localhost~]# su - user2

[user2@localhost~]$ mkdir /acltest/test2

[user2@localhost~]$ touch /acltest/file2.txt

[user2@localhost~]$ exit

logout

[root@localhost~]# getfacl /acltest/test* /acltest/file*  

//查看test1、test2、file1.txt以及file2.txt的acl策略

getfacl: Removing leading '/' from absolute path names

# file: acltest/test1

# owner: root

# group: root

user::rwx

user:user1:rwx

group::r-x

mask::rwx

other::r-x

default:user::rwx

default:user:user1:rwx

default:group::r-x

default:mask::rwx

default:other::r-x


# file: acltest/test2

# owner: user2

# group: user2

user::rwx

user:user1:rwx

group::r-x

mask::rwx

other::r-x

default:user::rwx

default:user:user1:rwx

default:group::r-x

default:mask::rwx

default:other::r-x


# file: acltest/file1.txt

# owner: root

# group: root

user::rw-

user:user1:rwx                  #effective:rw-

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

mask::rw-

other::r--


# file: acltest/file2.txt

# owner: user2

# group: user2

user::rw-

user:user1:rwx                  #effective:rw-

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

mask::rw-

other::r--


[root@localhost~]#


示例三:清除所有acl控制策略

清空刚才对/root目录和/acltest目录设置的acl策略

[root@localhost~]# setfacl -b /acltest/ /root/

[root@localhost~]# getfacl /acltest/ /root/ | grep user1

//注:这里有一个提示,意思为从绝对路径中移除根目录

//也就是说,实际上是搜不到关于/root目录和/acltest目录关于acl策略的

//不适用该提示,直接cd到根目录下使用相对路径即可。

getfacl: Removing leading '/' from absolute path names

[root@localhost~]# getfacl /acltest/ | grep user1

getfacl: Removing leading '/' from absolute path names

[root@localhost~]# cd /    //切换到根目录下

[root@localhost/]# getfacl acltest/

#file: acltest

#owner: root

#group: root

user::rwx

group::rwx

other::rwx


[root@localhost/]# getfacl acltest/ root/ | grep user1

//可以看到,关于对user1的策略已经清空了,这里无法查看到。

[root@localhost/]#


三:补充:

1,关于注释的第一和第四条

我新建了一个分区,格式化之后,将其挂载的时候设置为启用acl,这这时用

mount| grep 设备名可以看到是有acl支持的,但是用tune2fs不能看到

安装系统时的根目录是启用了acl的,使用tune2fs命令可以看到,但是用

mount| grep 设备名不可以看到有acl支持

具体操作:

[root@localhost/]# mount -o acl /dev/sda6 /data/sda6/

[root@localhost/]# mount | grep sda6

/dev/sda6on /data/sda6 type ext3 (rw,acl)

[root@localhost/]# tune2fs -l /dev/sda2 | grep acl

Defaultmount options:    user_xattr acl

[root@localhost/]# df -h /

文件系统容量已用 可用 已用% 挂载点

/dev/sda2              19G  2.4G  16G  13% /

[root@localhost/]# tune2fs -l /dev/sda2 | grep acl

Defaultmount options:    user_xattr acl

[root@localhost/]# mount | grep sda2

/dev/sda2on / type ext3 (rw)


2,关于对一个文件设置了acl策略的效果

思路:

使用user2在/acltest(/acltest是没有acl策略的)建立一个文件file2.txt

将其权限设置为只有所有者具有rw权限

使用setfacl指定一条策略为user1对file2.txt文件有可读写的权限

测试,user1是否能够修改该文件


[root@localhost/]# ll -d /acltest/

drwxrwxrwx4 root root 4096 02-20 23:53 /acltest/

[root@localhost/]# getfacl acltest/

#file: acltest

#owner: root

#group: root

user::rwx

group::rwx

other::rwx


[root@localhost/]# su - user2

[user2@localhost~]$ cd /acltest/

[user2@localhostacltest]$ touch file2.txt

[user2@localhostacltest]$ chmod 600 file2.txt

[user2@localhostacltest]$ ll file2.txt

-rw-------1 user2 user2 12 02-21 00:51 file2.txt

[user2@localhostacltest]$ echo user2 > file2.txt

[user2@localhostacltest]$ cat file2.txt

user2

[user2@localhostacltest]$ su - user1

口令:

[user1@localhost~]$ ls

[user1@localhost~]$ cd /acltest/

[user1@localhostacltest]$ ls

file2.txt

[user1@localhostacltest]$ echo user1 >> file2.txt

-bash:file2.txt: 权限不够

[user1@localhostacltest]$cat file2.txt

user2

[user2@localhostacltest]$ setfacl -m u:user1:rw- file2.txt

[user2@localhostacltest]$ getfacl file2.txt

# file: file2.txt

# owner: user2

# group: user2

user::rw-

user:user1:rw-

group::rw-

mask::rw-

other::r--


[user2@localhostacltest]$ su - user1

口令:

[user1@localhost~]$ ls

[user1@localhost~]$ cd /acltest/

[user1@localhostacltest]$ ls

file2.txt

[user1@localhostacltest]$ echo user1>>file2.txt

[user1@localhostacltest]$ cat file2.txt  //这时user1有权限写入

user2

user1

[user1@localhostacltest]$


3,关于删除一条acl规则:setfacl的-x参数

思路:

为扩展2里面的user2创建的/acltest/file2.txt文件添加条规则

setfacl-m u:user3:rw- file2.txt

使得user3具有读写权限,

然后将user3的权限删除


具体操作:

[user2@localhostacltest]$ setfacl -m u:user3:rw- file2.txt

[user2@localhostacltest]$ getfacl file2.txt

#file: file2.txt

#owner: user2

#group: user2

user::rw-

user:user1:rw-

user:user3:rw-       //现在有两条规则

group::---

mask::rw-

other::---


[user2@localhostacltest]$ su user3    

//使用su use3的时候可在当前目录切换用户

//使用su - user3的时候会直接切换到user3的家目录

口令:     //输入口令后当前用户将切换为user3,路径不变

[user3@localhostacltest]$ ls

file2.txt

[user3@localhostacltest]$ cat file2.txt

user2

user1

[user3@localhostacltest]$ echo user3 >> file2.txt

[user3@localhostacltest]$ cat file2.txt

user2

user1

user3

[user3@localhostacltest]$ exit

exit

[user2@localhostacltest]$ setfacl-x u:user3  file2.txt

//注:在百度百科里面搜索到的那个答案是错误的!!!

//-x选项后面不能接权限,只能写成-x u:用户名

[user2@localhostacltest]$ getfacl file2.txt

#file: file2.txt

#owner: user2

#group: user2

user::rw-

user:user1:rw-    //user3的那条规则删除掉了

group::---

mask::rw-

other::---


[user2@localhostacltest]$


Linux系统管理_用户和用户组http://murongqingqqq.blog.51cto.com/2902694/1360239

Linux系统管理_基本权限和归属:http://murongqingqqq.blog.51cto.com/2902694/1360265

Linux系统管理_附加控制权限:http://murongqingqqq.blog.51cto.com/2902694/1360874






本文转自 murongqingqqq  51CTO博客,原文链http://blog.51cto.com/murongqingqqq/1361506接:

相关文章
|
1月前
|
安全 Shell Linux
【Shell 命令集合 系统管理 】Linux 锁定终端 vlock命令 使用指南
【Shell 命令集合 系统管理 】Linux 锁定终端 vlock命令 使用指南
35 1
|
1月前
|
监控 Shell Linux
【Shell 命令集合 系统管理 】Linux 显示当前登录到系统的用户信息 who命令 使用指南
【Shell 命令集合 系统管理 】Linux 显示当前登录到系统的用户信息 who命令 使用指南
43 1
|
1月前
|
监控 Shell Linux
【Shell 命令集合 系统管理 】Linux 显示目前登入系统的用户信息 w命令 使用指南
【Shell 命令集合 系统管理 】Linux 显示目前登入系统的用户信息 w命令 使用指南
44 2
|
1月前
|
存储 Shell Linux
【Shell 命令集合 系统管理 】Linux 修改用户的属性和配置 usermod命令 使用指南
【Shell 命令集合 系统管理 】Linux 修改用户的属性和配置 usermod命令 使用指南
30 1
|
1月前
|
搜索推荐 Shell Linux
【Shell 命令集合 系统管理 】Linux 管理用户配置文件 userconf命令 使用指南
【Shell 命令集合 系统管理 】Linux 管理用户配置文件 userconf命令 使用指南
37 2
|
1月前
|
Shell Linux 数据库
【Shell 命令集合 系统管理 】Linux 创建新用户的命令 useradd命令 使用指南
【Shell 命令集合 系统管理 】Linux 创建新用户的命令 useradd命令 使用指南
47 1
|
15天前
|
Linux 网络安全
linux免密登录报错 Bad owner or permissions on /etc/ssh/ssh_config.d/05-redhat.conf
linux免密登录报错 Bad owner or permissions on /etc/ssh/ssh_config.d/05-redhat.conf
23 1
|
15天前
|
安全 Unix Linux
一、linux 常用命令之 linux版本信息 系统管理与设置 持续更新******
一、linux 常用命令之 linux版本信息 系统管理与设置 持续更新******
16 0
|
1月前
|
网络协议 Shell Linux
【Shell 命令集合 系统管理 】Linux 查询域名的注册信息 whois命令 使用指南
【Shell 命令集合 系统管理 】Linux 查询域名的注册信息 whois命令 使用指南
48 1
|
1月前
|
存储 Shell Linux
【Shell 命令集合 系统管理 】Linux 显示当前登录用户的用户 whoami命令 使用指南
【Shell 命令集合 系统管理 】Linux 显示当前登录用户的用户 whoami命令 使用指南
49 1