練習
上課練習
1、 當用戶xiaoming對/testdir 目錄無執行權限時,意味著無法做哪些操作?
能查看文件大小,不能進入此目錄,不能在此目錄創建文件 能看到目錄中的內容,不能查看目錄內的大小及屬性,僅能查看目錄的相關屬性
[xiaoming@localhost ~]$ ll -d qin drwxrwxrw-. 2 root root 6 8月 3 22:10 qin [xiaoming@localhost ~]$ ll -a qin ls: 無法訪問qin/.: 權限不夠 ls: 無法訪問qin/..: 權限不夠 總用量 0 d????????? ? ? ? ? ? . d????????? ? ? ? ? ? .. [root@localhost xiaoming]# su xiaoming [xiaoming@localhost ~]$ cd qin bash: cd: qin: 權限不夠 [xiaoming@localhost ~]$ ll qin 總用量 0 [xiaoming@localhost ~]$ touch qin/asd touch: 無法創建"qin/asd": 權限不夠
2、 當用戶xiaoqiang對/testdir 目錄無讀權限時,意味著無法做哪些操作?
可以進入目錄,可以在目錄中創建文件,無法查看目錄里面的內容
[root@localhost qiuzhaoxian]# ll 總用量 2360 drwxrwx-wx. 3 xiaoming xiaoming 30 8月 4 19:15 123 [t1@localhost /]$ cd /123/ [t1@localhost 123]$ ll ls: 無法打開目錄.: 權限不夠 [t1@localhost 123]$ touch asd [t1@localhost 123]$ echo dsad > asd [t1@localhost 123]$ ll -d /123 drwxrwx-wx. 3 xiaoming xiaoming 40 8月 4 19:19 /123
3、 當用戶wangcai 對/testdir 目錄無寫權限時,該目錄下的只讀文件file1是否可修改和刪除?
不能修改和刪除
[wangcai@localhost ~]$ echo hello > /testdir/file1 -bash: /testdir/file1: Permission denied [wangcai@localhost ~]$ echo hello >> /testdir/file1 不能修改 -bash: /testdir/file1: Permission denied [wangcai@localhost ~]$ rm /testdir/file1 rm: cannot remove ‘/testdir/file1’: Permission denied 不能刪除
4、 復制/etc/fstab文件到/var/tmp下,設置文件所有者為wangcai讀寫權限,所屬組為sysadmins組有讀寫權限,其他人無權限
[root@localhost /]# cp /etc/fstab /var/tmp/ [root@localhost /]# chown wangcai:sysadmins /var/tmp/fstab [root@localhost /]# ll /var/tmp/fstab -rw-r--r--. 1 wangcai sysadmins 501 8月 4 19:32 /var/tmp/fstab [root@localhost /]# chmod 660 /var/tmp/fstab [root@localhost /]# ll /var/tmp/fstab -rw-rw----. 1 wangcai sysadmins 501 8月 4 19:32 /var/tmp/fstab
5、 誤刪除了用戶wangcai的家目錄,請重建并恢復該用戶家目錄及相應的權限屬性
mkdir /home/wangcai cp -r /etc/skel/. /home/wangcai chmod 700 /home/wangcai/
作業
在/data/testdir 里創建的新文件自動屬于g1 組,組g2 的成員如:alice 能對這些新文件有讀寫權限,組g3 的成員如:tom 只能對新文件有讀權限,其它用戶(不屬于g1,g2,g3)不能訪問這個文件夾
[root@localhost ~]# mkdir -p /data/testdir [root@localhost ~]# groupadd g1 [root@localhost ~]# groupadd g2 [root@localhost ~]# groupadd g3 [root@localhost ~]# cd /data [root@localhost data]# chgrp g1 testdir/ [root@localhost data]# chmod 2770 testdir/ [root@localhost data]# ll -d testdir/ drwxrws---. 2 root g1 6 Aug 3 19:15 testdir/ [root@localhost data]# setfacl -m g:g2:rwx testdir/ //設置g2組用戶對testdir目錄有權限 [root@localhost data]# setfacl -m g:g3:rwx testdir/ //設置g3組對testdir目錄有權限 [root@localhost data]# setfacl -m d:g:g2:rw testdir/ 設置默認g2組內成員對目錄內操作的權限 [root@localhost data]# setfacl -m d:g:g3:r testdir/ [root@localhost data]# gpasswd -a alice g2 Adding user alice to group g2 [root@localhost data]# gpasswd -a tom g3 Adding user tom to group g3 [root@localhost data]# su alice [alice@localhost data]$ cd testdir/ [alice@localhost testdir]$ touch f [alice@localhost testdir]$ getfacl f # file: f # owner: alice # group: g1 user::rw- group::rwx #effective:rw- group:g2:rw- group:g3:r-- mask::rw- other::---
設置/testdir/f1的權限,使user1用戶不可以讀寫執行,g1組可以讀寫/testdir/dir的權限,
使新建文件自動具有acl權限:user1:rw,g1:—
備份/testdir目錄中所有文件的ACL,清除/testdir的所有ACL權限,并利用備份還原
touch f1 setfacl -m u:user1:0 f1 setfacl -m g:g1:rw f1 setfacl -m g:g1:rwx /testdir setfacl -m u:user1:rwx /testdi setfacl -m d:u:user1:rw /testdir/ setfacl -m d:g:g1:- /testdir/ getfacl ../testdir/ getfacl /testdir/f1 getfacl -R ../testdir/ >acl.sql setfacl -R -b /testdir setfacl -R --set-file=acl.sql /testdir/ getfacl /testdir/
原創文章,作者:qzx,如若轉載,請注明出處:http://www.www58058.com/29194