Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15819
  • 博文数量: 6
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 10
  • 用 户 组: 普通用户
  • 注册时间: 2015-12-16 22:49
文章分类
文章存档

2016年(2)

2015年(4)

我的朋友
最近访客

分类: LINUX

2016-01-13 17:25:26

setfac

setfacl

Linux命令——setfacl

命令setfacl- 设置文件访问控制列表

setfacl,顾名思义就是设置文件的ACL规则。

Acl(Access Control
List
)就是访问控制列表,最初好像是unix里面为了提供更高级的权限管理而搞出来的。

可能是被chmod命令的3个权限控制无法满足,而被迫搞出来的吧!

ACL的设置技巧

getfacl:取得某个文件/目录的ACL设置项目

setfacl:设置某个目录/文件的ACL规定

[root@kinggoo.com ~]# tune2fs -l /dev/hda1 | grep option

Default mount options: user_xattr acl

–help一下


[root@kinggoo.com~]# setfacl --help

setfacl2.2.39--set fileaccess control lists

Usage:setfacl[-bkndRLP]{-m|-M|-x|-X...}file... #
-m|-M|-x|-X

-m,--modify=acl modify the current ACL(s)of file(s)
#设置文件acl规则(s估计是sock文件)

-M,--modify-file=file readACL entries tomodify from file
#修改文件acl规则

-x,--remove=acl remove entries from the ACL(s)of file(s)
#删除文件的acl规则(s估计是sock文件)

-X,--remove-file=file readACL entries toremove from file
#删除文件的acl规则

-b,--remove-all remove all extended ACL entries #
删除所有扩展的acl规则,基本的acl规则(所有者,群组,其他)将被保留.

-k,--remove-default remove the defaultACL
#删除缺省的acl规则。如果没有缺省规则,将不提示.

--set=acl set the ACL of file(s),replacing the current
ACL.

--set-file=file readACL entries toset from file
#从文件中读设置ACL规则.

--mask dorecalculate the effective rights mask #重新计算有效权限,即使ACL
mask被明确指定.

-n,--no-mask don'trecalculate the effective rights mask
#不要重新计算有效权限。setfacl默认会重新计算ACL mask,除非mask被明确的制定.

-d,--default operations apply tothe defaultACL
#设定默认的acl规则,针对目录而言.

-R,--recursive recurse into subdirectories
#递归的对所有文件及目录进行操作.

-L,--logical logical walk,follow symbolic links
#跟踪符号链接,默认情况下只跟踪符号链接文件,跳过符号链接目录。

-P,--physical physical walk,donotfollow symbolic links
#跳过所有符号链接,包括符号链接文件。

--restore=file restore ACLs(inverse of`getfacl-R')
#从文件恢复备份的acl规则(这些文件可由getfacl
-R产生)。通过这种机制可以恢复整个目录树的acl规则。此参数不能和除--test以外的任何参数一同执行.

--test testmode(ACLs are notmodified)
#测试模式,不会改变任何文件的acl规则,操作后的acl规格将被列出.

-v,--version print version andexit #版本.

-h,--help thishelp text #不用说肯定是帮助了.


当使用-M,-X选项从文件中读取规则时,setfacl接受getfacl命令输出的格式。每行至少一条规则,以#开始的行将被视为注释.

其他的权限

setfacl命令可以识别以下的规则格式。

setfacl命令可以识别以下的规则格式。

[d[efault]:][u[ser]:]uid[:perms]

指定用户的权限,文件所有者的权限(如果uid没有指定)。

[d[efault]:]g[roup]:gid[:perms]

指定群组的权限,文件所有群组的权限(如果gid未指定)

[d[efault]:]m[ask][:][:perms]

有效权限掩码

[d[efault]:]o[ther][:perms]


#perms域是一个代表各种权限的字母的组合:读:r 写:w
执行:x,执行只适合目录和一些可执行的文件。perms域也可设置为八进制格式0~7。

#其他的权限

试验一下,创建一个文件,然后获取该文件的acl

[shell@kinggoo.com ~]# touch file.kinggoo

[shell@kinggoo.com ~]# getfacl file.kinggoo #获取acl

# file: file.kinggoo

# owner: root

# group: kinggoo

user::rw-

group::r--

other::r--

#给kinggoo.com用户向file.kingoo文件增加读和执行的acl规则

[shell@kinggoo.com ~]# setfacl -m u:kinggoo.com:rx
file.kinggoo

#查看user:kinggoo.com:r-x出来了吧,而且mask被默认被设置

[shell@kinggoo.com ~]# getfacl file.kinggoo

# file: file.kinggoo

# owner: root

# group: kinggoo

user::rw-

user:kinggoo.com:r-x

group::r--

mask::r-x

other::r--

#木有写用户的时候会修改默认文件所有者的权限

[shell@kinggoo.com ~]# setfacl -m u::rwx file.kinggoo

#最初是user:rw-,现在被修改rwx了

[shell@kinggoo.com ~]# getfacl file.kinggoo

# file: file.kinggoo

# owner: root

# group: kinggoo

user::rwx

user:kinggoo.com:r-x

group::r--

mask::r-x

other::r--

设置组的话只需要把setfacl -m u::rwx file.kinggoo中的u改为g即可,大致差不多。

设置mask的话,setfacl -m u::rwx
file.kinggoo中的u改为m,并且这个可不针对用户和组哦,其他的大致差不多。

在使用-R时,记得放在-m前面,否则不可以地

使用-d的话,就会把默认的都加上去,针对目录哦。设置文件会警告[setfacl: /root/a/file.kinggoo:
Only directories can have default ACLs]

mkdir一个目录

[shell@kinggoo.com ~]# mkdir directories.kinggoo

[shell@kinggoo.com ~]# setfacl -m u:kinggoo.com:x d.kinggoo/
#目录如果不加-d就会警告,所以-d要和目录使用

[shell@kinggoo.com ~]# setfacl: d.kinggoo/: No such file or
directory

[shell@kinggoo.com ~]# setfacl -d -m u:kinggoo.com:x
directories.kinggoo/#设置这个目录acl,并且使用-d参数

[shell@kinggoo.com ~]# getfacl directories.kinggoo

# file: directories.kinggoo

# owner: root

# group: kinggoo

user::rwx

group::r-x

other::r-x

default:user::rwx

default:user:kinggoo.com:--x

default:group::r-x

default:mask::r-x

default:other::r-x

去掉所有的acl规则

[shell@kinggoo.com ~]# setfacl -b directories.kinggoo/

[shell@kinggoo.com ~]# getfacl directories.kinggoo/

# file: directories.kinggoo

# owner: root

# group: kinggoo

user::rwx

group::r-x

other::r-x

去掉指定acl规则

#先查看一下文件默认的acl规则

[shell@kinggoo.com ~]# getfacl file.kinggoo

# file: file.kinggoo

# owner: root

# group: kinggoo

user::rwx

user:kinggoo.com:r-x #<----注意这里

group::r--

mask::r-x

other::r--

#然后执行-x参数

[shell@kinggoo.com ~]# setfacl -x u:kinggoo.com file.kinggoo

[shell@kinggoo.com ~]# getfacl file.kinggoo

# file: file.kinggoo

# owner: root

# group: vancl

user::rwx

group::r--#没有user:kinggoo.com:r-x这行了

mask::r--

other::r--

下面这个是我脚本里面写的一个东西,不过为了能起到例子的作用我把变量多数都改掉了(木有用在我的服务器哦)

${DocRoot}是一个变量,代表是一个文件夹目录!!!!!

设置两个用户的ACL

setfacl -R -m u:[user.kinggoo.com]:rw- ${DocRoot};

setfacl -R -m u:[user1.kinggoo.com]:rwx ${DocRoot};

setfacl -d -R -m u:[user.kinggoo.com]:rw- ${DocRoot};

setfacl -d -R -m u:[user1.kinggoo.com]:rw- ${DocRoot};

设置两个组的ACL

setfacl -R -m g:[group.kinggoo]:--- ${DocRoot};

setfacl -R -m g:[group1.kinggoo]:--- ${DocRoot};

setfacl -d -R -m g:[group.kinggoo]:--- ${DocRoot};

setfacl -d -R -m g:[group1.kinggoo]:--- ${DocRoot};

设置other的ACL

setfacl -R -m o::--- ${DocRoot};

setfacl -d -R -m o::--- ${DocRoot};

设置默认mask的ACL

setfacl -R -m m::rwx ${DocRoot};

setfacl -d -R -m m::rw- ${DocRoot};
阅读(1011) | 评论(0) | 转发(0) |
0

上一篇:USB接口的移动硬盘如何接入LINUX系统

下一篇:没有了

给主人留下些什么吧!~~