扩展权限ACL的应用

<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} -->

文件扩展权限限制 ACL

用户大家对 Linux/Unix UGO 权限管理方式一定不陌生. 为了实现一些比较复杂的权限管理,往往不得不创建很多的组,并加以详细的记录和区分这是一件很麻烦的事。为了能使某一个用户对某一文件指定一个权限,比如对某一个特定的文件,用户A 可以读取,用户B 所在的组可以修改,惟独用户B 不可以……。于是就有了IEEE POSIX 1003.1e 这个ACL 的标准。ACL 的出现专门解决了这个问题。下面我们来探讨下ACL 在实际生活中的应用。

扩展acl 的一些基本语法

getfacl  -d     文件的默认权限

setfacl  -m     设置扩展权限

              |u  针对用户设置扩展权限

              |g   针对组置扩展权限

              |d     设置默认权限

              |m   设定统一收回么个选项

       -k    移除默认acl 条目

       -R     权限递归

       -x      取消特定权限

setfacl   -    取消宽展权限

首先我们要在linux 加载硬盘acl 功能的支持

    #vim  /etc/fstab

   /rich    ext3    defaults,acl    1 2

default 后面加入acl 然后重新挂载硬盘

#mount o remount | /home

查看验证下是否添加成功

#mount (看/etc/fstab 中添加的内容是否正常出现)新文件apple

#touch  apple

#getfacl  apple

#su  -  aaa

$vim  /root/apple

这里我们发现permission   denied 无写权限

$su  -  root

#setfacl  u:aaa rwx

$vim   /root/apple

这里我们就可以正常写入了,我们下面添加一个组

$su -  root

#getfacl  g:nasasha:rw

#su  -  nasasha

$vim  /root/apple

 

 

 

 

 

 

 

#  touch file1

#  ls -l file1

-rw-r--r-- 1 root root     7 Dec 11 00:28 file1

 

查看文件缺省的ACL ,这时这个文件除了通常的UGO 的权限之外,并没有ACL

 

#  getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

group::r--

other::r-

 

下面添加几个用户和组,一会我将使用ACL 赋予他们不同的权限:

 

#  groupadd testg1

#  useradd testu1

#  useradd testu2

#  usermod -G testg1 testu1

 

切换到用户testu1

 

# su testu1

$ echo "testu1" >> file1

bash: file1: Permission denied

 

失败了。因为file1 并不允许除了root 以外的用户写。我们现在就通过修改file1ACL 赋予testu1 足够的权限:

 

# setfacl -m u:testu1:rw file1

# su testu1

$ echo "testu1" >> file1

$ cat file1

testu1

 

修改成功了,用户testu1 可以对file1 做读写操作了。我们来看一下file1ACL

 

$ getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

user:testu1:rw-

group::r--

mask::rw-

other::r-

 

我们ls 看一下:

 

# ls -l file1

-rw-rw-r--+ 1 root root     7 Dec 11 00:28 file1

 

如果仔细看的话,我们会发现权限末尾有个“+ ”号 ,这个说明file1 设置了ACL , 接下来我们修改一下testu1 的权限,同时给testg1 这个组以读的权限:

 

# setfacl -m u:testu1:rwx,g:testg1:r file1

# getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

user:testu1:rwx

group::r--

group:testg1:r--

mask::rwx

other::r-

 

 

# setfacl -m mask::r file1]# getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

user:testu1:rwx                  #effective:r--

group::r--

group:testg1:r--

mask::r--

other::r--

 

# ls -l file1

-rw-r--r--+ 1 root root 7 Dec 11 00:28 file1

 

删除已有的ACL

 

# setfacl -x g:testg1 file1

# getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

user:testu1:rwx

group::r--

mask::rwx

other::r--

 

我们看到testg1 的权限已经被去掉了。如果需要去掉所有的ACL 可以用-b 选项。所有的ACL 项都会被去掉。

 

# setfacl -b file1

# getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

group::r--

other::r--

 

 

# setfacl --set u::rw,u:testu1:rw,g::r,o::- file1

# getfacl file1

# file: file1

# owner: root

# group: root

user::rw-

user:testu1:rw-

group::r--

mask::rw-

other::---

 

目录的默认ACL

 

]# setfacl -d --set g:testg1:rwx dir1

]# getfacl dir1

# file: dir1

# owner: root

# group: root

user::rwx

group::r-x

other::r-x

default:user::rwx

default:group::r-x

default:group:testg1:rwx

default:mask::rwx

default:other::r-x

 

建立一个文件试试:

 

# touch dir1/file1

# getfacl dir1/file1

# file: dir1/file1

# owner: root

# group: root

user::rw-

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

group:testg1:rwx                #effective:rw-

mask::rw-

other::r--

 

备份和恢复ACL

 

# getfacl -R dir1 > dir1.acl

# ls -l dir1.acl

total 16

-rw-r--r--  1 root root   310 Dec 12 21:10 dir1.acl

 

我们用-b 选项删除所有的ACL 数据,来模拟从备份中回复的文件和目录:

 

 

# setfacl --restore dir1.acl

# getfacl -R dir1

# file: dir1

# owner: root

# group: root

user::rwx

group::r-x

other::r-x

default:user::rwx

default:group::r-x

default:group:testg1:rwx

default:mask::rwx

default:other::r-x

 

# file: dir1/file1

# owner: root

# group: root

user::rw-

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

group:testg1:rwx                #effective:rw-

mask::rw-

other::r--

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值