1. 在/data/testdir里創建的新文件自動屬于g1組,組g2的成員如: alice能對這些新文件有讀寫權限,
組g3的成員如: tom只能對新文件有讀權限,其它用戶(不屬于,g2,g3)不能訪問這個文件夾。
root@localhost ~]# mkdir -p /data/testdir [root@localhost ~]# groupadd g1 [root@localhost ~]# groupadd g2 [root@localhost ~]# groupadd g3 [root@localhost ~]# ll /data/testdir/ -d drwxr-xr-x. 2 root root 4096 7月 21 07:01 /data/testdir/ [root@localhost ~]# chmod g+s /data/testdir [root@localhost ~]# ll /data/testdir/ -d drwxr-sr-x. 2 root root 4096 7月 21 07:01 /data/testdir/ [root@localhost ~]# chown :g1 /data/testdir [root@localhost ~]# ll /data/testdir/ -d drwxr-sr-x. 2 root g1 4096 7月 21 07:01 /data/testdir/ [root@localhost ~]# useradd alice [root@localhost ~]# gpasswd -a alice g2 正在將用戶“alice”加入到“g2”組中 [root@localhost ~]# useradd tom [root@localhost ~]# gpasswd -a tom g3 正在將用戶“tom”加入到“g3”組中 [root@localhost ~]# setfacl -m d:g:g2:rw /data/testdir/ [root@localhost ~]# setfacl -m d:g:g3:r /data/testdir/ [root@localhost ~]# getfacl /data/testdir/ getfacl: Removing leading '/' from absolute path names # file: data/testdir/ # owner: root # group: g1 # flags: -s- user::rwx group::r-x other::r-x default:user::rwx default:group::r-x default:group:g2:rw- default:group:g3:r-- default:mask::rwx default:other::r-x [root@localhost ~]# chmod o= /data/testdir/ [root@localhost ~]# ll /data/testdir/ -d drwxr-s---+ 2 root g1 4096 7月 21 07:01 /data/testdir/ [root@localhost ~]# setfacl -m g:g2:rwx /data/testdir/ [root@localhost ~]# setfacl -m g:g3:rwx /data/testdir/ 創建新文件 touch /data/testdir/f2 g2組alice,對新文件f2可讀寫 [root@localhost ~]# su - alice [alice@localhost ~]$ cat /data/testdir/f2 [alice@localhost ~]$ echo "aaa" > /data/testdir/f2 [alice@localhost ~]$ cat /data/testdir/f2 aaa g3組:tom,對新文件只讀 [root@localhost ~]# su - tom [tom@localhost testdir]$ cat ./f2 [tom@localhost testdir]$ echo "a" >f2 -bash: f2: 權限不夠 其他用戶:user1,不能訪問目錄 [root@localhost ~]# su - user1 [user1@localhost testdir]$ cd /data/testdir/ -bash: cd: /data/testdir/: 權限不夠
2.設置user1,使之新建文件權限為rw——-
[user1@localhost ~]$ umask 066 [user1@localhost ~]$ touch b [user1@localhost ~]$ ll b -rw-------. 1 user1 user1 0 7月 21 04:23 b
3.設置/testdir/f1的權限,使user1用戶不可以讀寫執行,g1組可以讀寫
[root@localhost /]# setfacl -m u:user1:--- /testdir/f1 [root@localhost /]# getfacl /testdir/f1 getfacl: Removing leading '/' from absolute path names # file: testdir/f1 # owner: root # group: root user::rw- user:user1:--- group::r-- mask::r-- other::r-- [root@localhost /]# groupadd g1 [root@localhost /]# setfacl -m g:g1:rw /testdir/f1 [root@localhost /]# getfacl /testdir/f1 getfacl: Removing leading '/' from absolute path names # file: testdir/f1 # owner: root # group: root user::rw- user:user1:--- group::r-- group:g1:rw- mask::rw- other::r--
4./testdir/dir的權限,使新建文件自動具有acl權限:user1:rw,g1:—
[root@localhost /]# mkdir testdir/dir [root@localhost /]# setfacl -m d:u:user1:rw testdir/dir [root@localhost /]# setfacl -m d:g:g1:--- testdir/dir [root@localhost /]# getfacl testdir/dir # file: testdir/dir # owner: root # group: root user::rwx group::r-x other::r-x default:user::rwx default:user:user1:rw- default:group::r-x default:group:g1:--- default:mask::rwx default:other::r-x [root@localhost ~]# chmod o+w /testdir/dir/ [user1@localhost dir]$ touch /testdir/dir/f2 [user1@localhost dir]$ ll ./f2 -rw-rw-r--+ 1 user1 user1 0 7月 21 05:42 ./f2
5.備份/testdir目錄中所有文件的ACL,清除/testdir的所有ACL權限,并利用備份還原
[root@localhost ~]# getfacl /testdir/ getfacl: Removing leading '/' from absolute path names # file: testdir/ # owner: root # group: g1 # flags: -s- user::rwx group::r-x group:g2:rwx group:g3:rwx mask::rwx other::--- default:user::rwx default:group::r-x default:group:g2:rw- default:group:g3:r-- default:mask::rwx default:other::r-x [root@localhost ~]# getfacl -R /testdir/ > /tmp/acl.txt [root@localhost ~]# setfacl -b /testdir/ [root@localhost ~]# getfacl /testdir/ getfacl: Removing leading '/' from absolute path names # file: testdir/ # owner: root # group: g1 # flags: -s- user::rwx group::r-x other::--- [root@localhost ~]# setfacl -R --set-file=/tmp/acl.txt /testdir/ [root@localhost ~]# getfacl /testdir/ getfacl: Removing leading '/' from absolute path names # file: testdir/ # owner: root # group: g1 # flags: -s- user::rw- group::r-x #effective:r-- group:g2:rw- group:g3:r-- mask::rw- other::r-- default:user::rwx default:group::r-x default:group:g2:rw- default:group:g3:r-- default:mask::rwx default:other::r-x
6.當用戶xiaoming對/testdir 目錄無執行權限時,意味著無法做哪些操作?
[root@localhost ~]# ll /testdir/ -d drwxr-xrw-. 2 root root 4096 7月 21 10:07 /testdir/ [xiaoming@localhost /]$ cd testdir/ -bash: cd: testdir/: 權限不夠 [xiaoming@localhost /]$ ls /testdir/ ls: 無法訪問/testdir/aaa: 權限不夠 aaa [xiaoming@localhost /]$ ls -l /testdir/ ls: 無法訪問/testdir/aaa: 權限不夠 總用量 0 -????????? ? ? ? ? ? aaa 不能ls -l 此目錄 不能cd進此目錄
7.當用戶xiaoqiang對/testdir 目錄無讀權限時,意味著無法做哪些操作?
[root@localhost /]# su - xiaoqiang [xiaoqiang@localhost ~]$ cd /testdir/ [xiaoqiang@localhost testdir]$ ls ls: 無法打開目錄.: 權限不夠 [xiaoqiang@localhost testdir]$ ll ls: 無法打開目錄.: 權限不夠 [xiaoqiang@localhost testdir]$ rm -rf aaa 不能使用ls查看目錄下文件
8.當用戶wangcai 對/testdir 目錄無寫權限時,該目錄下的只讀文件file1是否可修改和刪除?
[root@localhost testdir]# ll file1 -rwxr-xr--. 1 root root 0 7月 21 10:30 file1 [root@localhost testdir]# su - wangcai [wangcai@localhost ~]$ cd /testdir/ [wangcai@localhost testdir]$ ls file1 [wangcai@localhost testdir]$ rm file1 rm:是否刪除有寫保護的普通空文件 "file1"?y rm: 無法刪除"file1": 權限不夠 [wangcai@localhost testdir]$ echo "a"> file1 -bash: file1: 權限不夠 不能修改,不能刪除
9.復制/etc/fstab文件到/var/tmp下,設置文件所有者為wangcai讀寫權限,所屬組為sysadmins組有讀寫權限,其他人無權限
[root@localhost ~]# cp /etc/fstab /var/tmp/ [root@localhost ~]# chown wangcai:sysadmins /var/tmp/fatsb [root@localhost ~]# chmod 660 /var/tmp/fatab [root@localhost ~]# ll /var/tmp/fstab 總用量 4 -rw-rw----. 1 root root 805 7月 21 10:33 fstab
10.誤刪除了用戶wangcai的家目錄,請重建并恢復該用戶家目錄及相應的權限屬性
cp /etc/skel/ /home/wangcai chown wangcai:wangcai /home/wangcai chmod 600 /home/wangcai
原創文章,作者:M20-1--孔祥文,如若轉載,請注明出處:http://www.www58058.com/28846