歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Red Hat Linux 7 下 ACL權限基本設置

Red Hat Linux 7 下 ACL權限基本設置

日期:2017/2/28 13:53:58   编辑:Linux教程

一 ACL簡介:

訪問控制列表(Access Control List,ACL) 是路由器和交換機接口的指令列表,用來控制端口進出的數據包。ACL適用於所有的被路由協議,如IP、IPX、AppleTalk等。

二 如何查看權限列表:

[linuxidc@foundation2 Desktop]$ ls -l file
-rw-rw-r-- . 1 root kiosk 0 Nov 7 09:19 file
如果此位為 “.” 代表這位沒有權限列表
如果此為 “+” 代表有權限列表存在

那麼我們首先給 file 文件加上權限列表

並且通過 ll 命令發現已經有了權限列表
則可以通過 getfacl 命令查看更加詳細的權限

[root@localhost Desktop]# setfacl -m u:student:rwx file
[root@localhost Desktop]# ll
total 4
-rw-rwxr--+ 1 root root 0 Nov 9 11:11 file
[root@localhost Desktop]# getfa
getfacl getfattr
[root@localhost Desktop]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
user:student:rwx
group::r--
mask::rwx
other::r--

那麼這些分別代表什麼呢
[root@localhost Desktop]$ getfacl file
# file: file 文件名稱
# owner: root 文件所有人
# group: kiosk 文件所有組
user::rw- 文件用戶權限
user:student:rwx 文件特定用戶權限
group::rw- 所有組權限
mask::rwx 特定用戶生效的最大權限
other::r-- 其他人權限

三 如何設定 acl 權限

由上圖 有設定方式,故下面是我的一些設定方式的總結

setfacl -m <u|g|m>:<username|groupname>:權限 filename acl設定方式

setfacl -b filname 刪除文件權限列表,一下子就全刪了,+號都沒有了
setfacl -x <u|g>:<username|groupname> filename 刪除特定權限的特定用戶或組

四 acl 默認權限
默認權限之針對目錄使用,是讓目錄中所有新建文件都繼承此權限

setfacl -m d:<u|g|o>:<username|group>:rwx directory
設定默認權限,這個權限對目錄本身不生效,只對裡面內容生效(新建的)

[root@localhost /]# mkdir /xp
[root@localhost /]# setfacl -m d:u:student:rwx /xp
[root@localhost /]# getfacl /xp
getfacl: Removing leading '/' from absolute path names
# file: xp
# owner: root
# group: root
user::rwx
group::r-x
other::r-x
default:user::rwx
default:user:student:rwx
default:group::r-x
default:mask::rwx
default:other::r-x
[root@localhost xp]# touch file
[root@localhost xp]# ll
total 4
-rw-rw-r--+ 1 root root 0 Nov 9 15:25 file
[root@localhost xp]# cat file
[root@localhost xp]#
由上面可知道other對於它只有r權限
那麼接下來我們用student 用戶試試有沒有剛才設定的權限(切記,權限加了之後才新建的file)

[root@localhost xp]# su - student
Last login: Mon Nov 9 15:24:51 EST 2015 on pts/0
[student@localhost ~]$ cd /xp
[student@localhost xp]$ echo hello,world >file
[student@localhost xp]$ cat file
hello,world
顯然已經成功,不過只是對新建的文件產生作用,以前存在的不受影響。

setfacl -x d:<u|g|o>:<username|group> directory
撤銷目錄中某條默認權限

setfacl -b directory
刪除文件權限列表

[root@localhost xp]# setfacl -x d:u:student file
[root@localhost xp]# getfacl file
# file: file
# owner: root
# group: root
user::rw-
user:student:rwx #effective:rw-
group::r-x #effective:r--
mask::rw-
other::r--

[root@localhost xp]# setfacl -b file
[root@localhost xp]# ll
total 4
-rw-r--r--. 1 root root 12 Nov 9 15:30 file

更多RedHat相關信息見RedHat 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=10

Copyright © Linux教程網 All Rights Reserved