課上練習
1.當用戶xiaoming 對/testdir 目錄無執行權限時,意味著無法做哪些操作?
drwxr-xr–. 14 root root 4096 Aug 3 13:35 /testdir
[xiaoming@localhost ~]$ touch /testdir/f1 touch: cannot touch ‘/testdir/f1’: Permission denied 不能創建 [xiaoming@localhost ~]$ ll /testdir/aa ls: cannot access /testdir/aa: Permission denied 不能訪問 [xiaoming@localhost ~]$ cd /testdir -bash: cd: /testdir: Permission denied 不能進入 [xiaoming@localhost ~]$ rm /testdir/aa rm: cannot remove ‘/testdir/aa’: Permission denied 不能刪除
2.當用戶xiaoqiang 對/testdir 目錄無讀權限時,意味著無法做哪些操作?
drwxr-x-wx. 14 root root 4096 Aug 3 18:24 /testdir
[xiaoqiang@localhost ~]$ cd /testdir [xiaoqiang@localhost testdir]$ ls ls: cannot open directory .: Permission denied 不能看里面文件名 [xiaoqiang@localhost ~]$ echo word > /testdir/x1 [xiaoqiang@localhost ~]$ echo word2 >> /testdir/x1 [xiaoqiang@localhost ~]$ cat /testdir/x1 word word2 [xiaoqiang@localhost ~]$ rm /testdir/x1 [xiaoqiang@localhost ~]$ rm /testdir/file1 rm: remove write-protected regular file ‘/testdir/file1’? y //目錄權限w:可以創建或刪除目錄中文件,配合x(無視文件的權限,因為文件是目錄中的內容,一個名字)
3.當用戶wangcai 對/testdir 目錄無寫權限時,該目錄下的只讀文件file1 是否能修改和刪除?
drwxr-xr–. 14 root root 4096 Aug 3 18:24 /testdir
-r–r–r–. 1 root root 0 Aug 3 18:24 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 ~]# chmod ug=rw,o= /var/tmp/fstab [root@localhost ~]# ll /var/tmp/fstab -rw-rw----. 1 wangcai sysadmins 465 Aug 3 18:13 /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/ [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權限,并利用備份還原
cd /testdir touch f1 setfacl -m u:user1:0 f1 mkdir dir setfacl -m g:g1:rw dir setfacl -m d:u:user1:rw dir setfacl -m d:g:g1:0 dir touch dir/{aa,bb,cc} getfacl -R dir/ > /bak/bak.acl setfacl -R -b * setfacl -R --set-file=/bak/bak.acl /testdir/dir/
設置user1,使之新建文件權限為rw——-
[user1@localhost ~]$ umask 0066
原創文章,作者:victorycommander,如若轉載,請注明出處:http://www.www58058.com/28188
每一步都寫的很詳細,但是能把操作結果總結成一句話就更好的。