国产精品香蕉在线观看网,亚洲欧美精品综合在线观看,亚洲不卡av一区二区无码不卡,亚洲日本精品国产第一区二区

移動(dòng)安全 安全管理 應(yīng)用案例 網(wǎng)絡(luò)威脅系統(tǒng)安全 應(yīng)用安全 數(shù)據(jù)安全 云安全
當(dāng)前位置: 主頁(yè) > 信息安全 > 系統(tǒng)安全 >

在Linux中使用訪問(wèn)控制列表(ACL)保護(hù)文件/目錄

時(shí)間:2014-06-04 13:23來(lái)源:TuZhiJiaMi企業(yè)信息安全專家 點(diǎn)擊:
作為系統(tǒng)管理員,我們的首要任務(wù)就是切實(shí)保護(hù)數(shù)據(jù)的安全,以免被未授權(quán)的人訪問(wèn)。我們都很清楚使用一些大有幫助的Linux命令設(shè)置的權(quán)限,比如chmod、chown和chgrp等命令,可是這些默認(rèn)的權(quán)限
Tags系統(tǒng)安全(735)Linux(46)ACL(5)  

  作為系統(tǒng)管理員,我們的首要任務(wù)就是切實(shí)保護(hù)數(shù)據(jù)的安全,以免被未授權(quán)的人訪問(wèn)。我們都很清楚使用一些大有幫助的Linux命令設(shè)置的權(quán)限,比如chmod、chown和chgrp等命令,可是這些默認(rèn)的權(quán)限集有一定的局限性,有時(shí)可能還滿足不了我們的要求。比如說(shuō),我們就無(wú)法針對(duì)同一目錄或文件為不同用戶設(shè)置不同的權(quán)限集。因而,訪問(wèn)控制列表(ACL)應(yīng)運(yùn)而生。

在Linux中使用訪問(wèn)控制列表(ACL)保護(hù)文件/目錄

  Linux訪問(wèn)控制列表

  比如說(shuō),你有三個(gè)用戶,分別是“tecmint1”、“tecmint2”和“tecmint3”。每個(gè)用戶都有一個(gè)共同的用戶組,比如說(shuō)“acl”。用戶“tecmint1”希望,只有“tecmint2”用戶才能讀取和訪問(wèn)歸“tecmint1”用戶所有的文件,其他人都無(wú)權(quán)訪問(wèn)該文件。

  訪問(wèn)控制列表(ACL)讓我們可以做到同樣這點(diǎn)。這些ACL讓我們可以為某個(gè)用戶、用戶組或不在用戶組列表中的任何用戶的任何組授予權(quán)限。

  注意:按照紅帽產(chǎn)品說(shuō)明文檔,它為ext3文件系統(tǒng)和NFS導(dǎo)出文件系統(tǒng)提供了ACL支持。

  如何檢查L(zhǎng)inux系統(tǒng)中的ACL支持?

  在繼續(xù)下一步之前,你應(yīng)確保ACL在現(xiàn)有的內(nèi)核和已掛載的文件系統(tǒng)上得到支持。

  1. 檢查內(nèi)核是否支持ACL。

  運(yùn)行下面這個(gè)命令,檢查是否為文件系統(tǒng)提供ACL支持,是否有POSIX_ACL=Y選項(xiàng)(如果出現(xiàn)的是N,而不是Y,那么這意味著內(nèi)核并不支持ACL,需要重新加以編譯)。

  [root@linux ~]# grep -i acl /boot/config*CONFIG_EXT4_FS_POSIX_ACL=yCONFIG_REISERFS_FS_POSIX_ACL=yCONFIG_JFS_POSIX_ACL=yCONFIG_XFS_POSIX_ACL=yCONFIG_BTRFS_FS_POSIX_ACL=yCONFIG_FS_POSIX_ACL=yCONFIG_GENERIC_ACL=yCONFIG_TMPFS_POSIX_ACL=yCONFIG_NFS_V3_ACL=yCONFIG_NFSD_V2_ACL=yCONFIG_NFSD_V3_ACL=yCONFIG_NFS_ACL_SUPPORT=mCONFIG_CIFS_ACL=yCONFIG_9P_FS_POSIX_ACL=y

  2. 檢查所需的程序包。

  在開始處理ACL之前,要確保你已安裝了所需的程序包。下面是所需的程序包,需要使用yum或apt-get命令加以安裝。

  [root@linux ~]# yum install nfs4-acl-tools acl libacl [on RedHat based systems][tecmint@linux ~]$ sudo apt-get install nfs4-acl-tools acl [on Debian based systems]

  3. 檢查已掛載的文件系統(tǒng)是否支持ACL。

  現(xiàn)在,檢查已掛載的文件系統(tǒng)是否使用ACL選項(xiàng)掛載的。我們可以使用“mount”命令來(lái)進(jìn)行同樣的檢查,如下所示。

  [root@linux ~]# mount | grep -i root/dev/mapper/fedora-root on / type ext4 (rw,relatime,data=ordered)

  但在本例中,它在默認(rèn)情況下沒(méi)有顯示acl。所以,接下來(lái)我們可以再次使用acl選項(xiàng),重新掛載已掛載的分區(qū)。但在繼續(xù)下一步之前,我們還有另一個(gè)選項(xiàng):確保有沒(méi)有使用acl選項(xiàng)來(lái)掛載,因?yàn)閷?duì)較新系統(tǒng)而言,它可能整合了默認(rèn)的掛載選項(xiàng)。

  [root@linux ~]# tune2fs -l /dev/mapper/fedora-root | grep aclDefault mount options: user_xattr acl

  在上面的輸出結(jié)果中,你能看到默認(rèn)的掛載選項(xiàng)已經(jīng)支持acl。另一個(gè)選項(xiàng)是,重新掛載分區(qū),如下所示。

  [root@linux ~]# mount -o remount,acl /

  下一步,將下面這一項(xiàng)條目添加到/etc/fstab文件,讓其具有永久性。

  /dev/mapper/fedora-root / ext4 defaults,acl 1 1

  再次重新掛載分區(qū)。

  [root@linux ~]# mount -o remount /

  4. 針對(duì)NFS服務(wù)器。

  在NFS服務(wù)器上,如果NFS服務(wù)器導(dǎo)出的文件系統(tǒng)支持ACL,ACL又可以被NFS客戶機(jī)讀取,那么客戶機(jī)系統(tǒng)就能使用ACL。

  想禁用NFS共享區(qū)上的ACL,你就得在NFS服務(wù)器的“/etc/exportfs”文件中添加選項(xiàng)“no_acl”。想在NSF客戶端禁用它,那么在掛載期間再次使用“no_acl“選項(xiàng)。

  如何在Linux系統(tǒng)中實(shí)現(xiàn)ACL支持?

  ACL有兩種類型:

  ◦訪問(wèn)ACL:訪問(wèn)ACL用于授予針對(duì)任何文件或目錄的權(quán)限。

  ◦默認(rèn)ACL:默認(rèn)ACL用于授予/設(shè)置只針對(duì)特定目錄的訪問(wèn)控制列表。

  訪問(wèn)ACL與默認(rèn)ACL之間的區(qū)別如下:

  ◦默認(rèn)ACL只能用在目錄級(jí)別。

  ◦在該目錄里面創(chuàng)建的任何子目錄或文件將從父目錄那里繼承ACL。另一方面,文件繼承默認(rèn)ACL作為其訪問(wèn)ACL。

  ◦我們使用“–d”來(lái)設(shè)置默認(rèn)ACL,默認(rèn)ACL是可選的。

  在設(shè)置默認(rèn)ACL之前

  想為特定的文件或目錄設(shè)置默認(rèn)ACL,可以使用“getfacl”命令。在下面這個(gè)例子中,getfacl用于為文件夾“Music”獲得默認(rèn)ACL。

  [root@linux ~]# getfacl Music/# 文件:Music/# 所有者:root# 用戶組:rootuser::rwxgroup::r-xother::r-xdefault:user::rwxdefault:group::r-xdefault:other::rw-

  設(shè)置默認(rèn)ACL之后

  想為特定的文件或目錄設(shè)置默認(rèn)ACL,使用“setfacl”命令。在下面這個(gè)例子中,setfacl命令將為文件夾“Music”設(shè)置新的ACL(讀取和執(zhí)行)。

  [root@linux ~]# setfacl -m d:o:rx Music/[root@linux ~]# getfacl Music/# 文件:Music/# 所有者:root# 用戶組:rootuser::rwxgroup::r-xother::r-xdefault:user::rwxdefault:group::r-xdefault:other::r-x

  如何設(shè)置新的ACL

  使用“setfacl”命令用于設(shè)置或修改任何文件或目錄。比如說(shuō),想為用戶“tecmint1”授予讀取和寫入權(quán)限。

  # setfacl -m u:tecmint1:rw /tecmint1/example

  如何查看ACL

  使用“getfacl”命令用于查看任何文件或目錄的ACL。比如說(shuō),想查看“/tecmint1/example”上的ACL,使用下面這個(gè)命令。

  # getfacl /tecmint1/example# 文件:tecmint1/example/# 所有者:tecmint1# 用戶組:tecmint1user::rwxuser:tecmint1:rwxuser:tecmint2:r--group::rwxmask::rwxother::---

  如何刪除ACL

  想刪除任何文件/目錄的ACL,我們可以使用x和b這兩個(gè)選項(xiàng),如下所示。

  # setfacl -x ACL file/directory # 只刪除文件/目錄的指定ACL

  # setfacl -b file/directory # 刪除文件/目錄的所有ACL

  不妨將ACL實(shí)現(xiàn)到下列場(chǎng)景。

  兩個(gè)用戶(tecmint1和tecmint2)都有共同的輔助組,名為“acl”。我們將創(chuàng)建歸“tecmint1”用戶所有的一個(gè)目錄,并為用戶“tecmint2”提供針對(duì)該目錄的讀取和執(zhí)行權(quán)限。

  第1步:創(chuàng)建兩個(gè)用戶,并清除兩個(gè)用戶的密碼。

  [root@linux ~]# for user in tecmint1 tecmint2> do> useradd $user> passwd -d $user> doneRemoving password for user tecmint1.passwd: SuccessRemoving password for user tecmint2.passwd: Success

  第2步:為輔助組創(chuàng)建用戶組和用戶。

  [root@linux ~]# groupadd acl[root@linux ~]# usermod -G acl tecmint1 [root@linux ~]# usermod -G acl tecmint2

  第3步:創(chuàng)建目錄/tecmint,并將所有權(quán)改為tecmint1。

  [root@linux ~]# mkdir /tecmint1[root@linux ~]# chown tecmint1 /tecmint1/[root@linux ~]# ls -ld /tecmint1/drwxr-xr-x 2 tecmint1 root 4096 Apr 17 14:46 /tecmint1/[root@linux ~]# getfacl /tecmint1getfacl: Removing leading '/' from absolute path names# 文件:tecmint1# 所有者:tecmint1# 用戶組:rootuser::rwxgroup::r-xother::r-x

  第4步:以tecmint1身份登錄,在/tecmint文件夾下創(chuàng)建一個(gè)目錄。

  [tecmint@linux ~]$ su - tecmint1Last login: Thu Apr 17 14:49:16 IST 2014 on pts/4[tecmint1@linux ~]$ cd /tecmint1/[tecmint1@linux tecmint1]$ mkdir example[tecmint1@linux tecmint1]$ lltotal 4drwxrwxr-x 2 tecmint1 tecmint1 4096 Apr 17 14:50 example[tecmint1@linux tecmint1]$ whoami tecmint1

  第5步:現(xiàn)在使用“setfacl”設(shè)置ACL,那樣“tecmint1”用戶會(huì)擁有所有的rwx(讀取、寫入和執(zhí)行)權(quán)限,“tecmint2”用戶只有“example”文件夾上的讀取權(quán)限,其他用戶沒(méi)有任何權(quán)限。

  $ setfacl -m u:tecmint1:rwx example/$ setfacl -m u:tecmint2:r-- example/$ setfacl -m other:--- example/$ getfacl example/# 文件:example# 所有者:tecmint1# 用戶組:tecmint1user::rwxuser:tecmint1:rwxuser:tecmint2:r--group::r-xmask::rwxother::---

  第6步:現(xiàn)在以另一用戶(即“tecmint2”)的身份在另一個(gè)終端上登錄,將目錄改為“/tecmint1”?,F(xiàn)在試著使用“l(fā)s”命令,查看內(nèi)容,然后試著更改目錄,看看有什么區(qū)別,如下所示。

  [tecmint@linux ~]$ su - tecmint2Last login: Thu Apr 17 15:03:31 IST 2014 on pts/5[tecmint2@linux ~]$ cd /tecmint1/[tecmint2@linux tecmint1]$ ls -lR example/example/:total 0[tecmint2@linux tecmint1]$ cd example/-bash: cd: example/: Permission denied[tecmint2@linux tecmint1]$ getfacl example/# 文件:example# 所有者:tecmint1# 用戶組:tecmint1user::rwxuser:tecmint1:rwxuser:tecmint2:r--group::rwxmask::rwxother::---

  第7步:現(xiàn)在為“tecmint2”用戶授予針對(duì)“example”文件夾的“執(zhí)行”權(quán)限,然后使用“cd”命令看看有什么效果?,F(xiàn)在,“tecmint2”用戶擁有查看和更改目錄的權(quán)限,但沒(méi)有寫入任何內(nèi)容的權(quán)限。

  [tecmint1@linux tecmint1]$ setfacl -m u:tecmint2:r-x example/[tecmint1@linux tecmint1]$ getfacl example/# 文件:example# 所有者:tecmint1# 用戶組:tecmint1user::rwxuser:tecmint1:rwxuser:tecmint2:r-xgroup::rwxmask::rwxother::---[tecmint@linux ~]$ su - tecmint2Last login: Thu Apr 17 15:09:49 IST 2014 on pts/5[tecmint2@linux ~]$ cd /tecmint1/[tecmint2@linux tecmint1]$ cd example/[tecmint2@linux example]$ getfacl .[tecmint2@linux example]$ mkdir testmkdir: cannot create directory 'test': Permission denied[tecmint2@linux example]$ touch testtouch: cannot touch 'test': Permission denied

  注意:實(shí)現(xiàn)ACL后,你會(huì)看到“l(fā)s –l”輸出有一個(gè)額外的“+”符號(hào),如下所示。

  [root@linux tecmint1]# lltotal 4drwxrwx---+ 2 tecmint1 tecmint1 4096 Apr 17 17:01 example

------分隔線----------------------------

推薦內(nèi)容