課堂練習:
1、在/data/testdir里創建的新文件自動屬于g1組,組g2的成員如:alice能對這些新文件有讀寫權限,組g3的成員如:tom只能對新文件有讀權限,其它用戶(不屬于g1,g2,g3)不能訪問這個文件夾。
[root@centos6 ~]# groupadd g1 [root@centos6 ~]# groupadd g2 [root@centos6 ~]# groupadd g3 [root@centos6 ~]# useradd -G g2 alice [root@centos6 ~]# useradd -G g3 tom [root@centos6 ~]# id alice uid=501(alice) gid=504(alice) groups=504(alice),502(g2) [root@centos6 ~]# id tom uid=502(tom) gid=505(tom) groups=505(tom),503(g3) [root@centos6 ~]# mkdir -p /data/testdir [root@centos6 ~]# cd /data/ [root@centos6 data]# ll total 4 drwxr-xr-x. 2 root root 4096 Aug 6 19:06 testdir [root@centos6 data]# chgrp g1 testdir/ [root@centos6 data]# chmod g+sw,o= testdir/ [root@centos6 data]# ll total 4 drwxrws---. 2 root g1 4096 Aug 6 19:06 testdir [root@centos6 data]# setfacl -m g:g2:rwx,g:g3:rwx testdir/ [root@centos6 data]# setfacl -m d:g:g2:rw,d:g:g3:r testdir/ [root@centos6 data]# getfacl testdir/ # file: testdir/ # owner: root # group: g1 # flags: -s- user::rwx group::rwx group:g2:rwx group:g3:rwx mask::rwx other::--- default:user::rwx default:group::rwx default:group:g2:rw- default:group:g3:r-- default:mask::rwx default:other::--- [root@centos6 data]#
作業:
1、設置user1,使之新建文件權限為rw——-
[user1@centos6 ~]$ echo "umask 0066" >> .bashrc [user1@centos6 ~]$ . .bashrc [user1@centos6 ~]$ umask 0066 [user1@centos6 ~]$ touch file1 [user1@centos6 ~]$ ls -l file1 -rw-------. 1 user1 user1 0 Aug 6 19:16 file1 [user1@centos6 ~]$
2、設置/testdir/f1的權限,使user1用戶不可以讀寫執行,g1組可以讀寫/testdir/dir的權限,使新建文件自動具有acl權限:user1:rw,g1:—,備份/testdir目錄中所有文件的ACL,清除/testdir的所有ACL權限,并利用備份還原
[root@centos6 testdir]# ls -ld . drwxr-xr-x. 2 root root 4096 Aug 6 20:25 . [root@centos6 testdir]# mkdir -p /testdir/dir/ [root@centos6 testdir]# touch f1 [root@centos6 testdir]# setfacl -m u:user1:0,g:g1:rw /testdir/f1 [root@centos6 testdir]# setfacl -m d:u:user1:rw,d:g:g1:0 /testdir/dir/ [root@centos6 testdir]# getfacl -R * > /root/acl.txt [root@centos6 testdir]# setfacl -R --set-file=/root/acl.txt /testdir/dir
3、三種權限rwx對文件和目錄的不同意義
文件的權限意義
r: 可使用文件查看類工具獲取其內容; w: 可修改其內容; x: 可以把此文件提請內核啟動為一個進程
目錄的權限意義
r: 可以使用ls查看此目錄中文件列表; w: 可在此目錄中創建文件,也可刪除此目錄中的文件; x: 可以使用ls -l查看此目錄中文件列表,可以cd進入此目錄;
4、umask和acl mask 的區別和聯系
umask:從目錄或文件上屏蔽掉最大權限相應的位,從而得出默認權限 acl:為指定用戶或用戶組添加權限 mask:控制acl列表中用戶的最高權限
5、三種特殊權限的應用場景和作用
SUID
作用:任何一個可執行程序文件能不能啟動為進程:取決發起者對程序文件是否擁有執行權限,啟動為進程之后,其進程的屬主為原程序文件的屬主 場景:啟動為進程之后,其進程的屬主為原程序文件的屬主,SUID只對二進制可執行程序有效,SUID設置在目錄上無意義
SGID
作用:任何一個可執行程序文件能不能啟動為進程:取決發起者對程序文件是否擁有執行權限;啟動為進程之后,其進程的屬主為原程序文件的屬組 場景:默認情況下,用戶創建文件時,其屬組為此用戶所屬的主組;一旦某目錄被設定了SGID,則對此目錄有寫權限的用戶在此目錄中創建的文件所屬的組為此目錄的屬組;通常用于創建一個 協作目錄
SGID
作用:具有寫權限的目錄通常用戶可以刪除該目錄中的任何文件,無論該文件的權限或擁有權 場景:在目錄設置Sticky 位,只有文件的所有者或root可以刪除該文件;sticky 設置在文件上無意義
原創文章,作者:Aleen,如若轉載,請注明出處:http://www.www58058.com/30181