1、當用戶xiaoming對/testdir 目錄無執行權限時,意味著無法做哪些操作?
[root@centos7 testdir]# ls -ld /testdir/ drwxr-xrw-. 3 root root 27 Aug 5 08:38 /testdir/ [root@centos7 testdir]# su xiaoming [xiaoming@centos7 testdir]$ ls ls: cannot open directory .: Permission denied [xiaoming@centos7 testdir]$ cd dir bash: cd: dir: Permission denied [xiaoming@centos7 testdir]$ ll /testdir ls: cannot access /testdir/file: Permission denied ls: cannot access /testdir/dir: Permission denied total 0 ?????????? ? ? ? ? ? dir ?????????? ? ? ? ? ? file [xiaoming@centos7 testdir]$ rm -rf dir rm: cannot remove ‘dir’: Permission denied [xiaoming@centos7 testdir]$ rm -f file rm: cannot remove ‘file’: Permission denied [xiaoming@centos7 testdir]$
從上訴實驗可知,不能ls查看此目錄和目錄元數據,不能cd切換到此目錄中,也不能刪除目錄中的文件文件夾
2、當用戶xiaoming對/testdir 目錄無讀權限時,意味著無法做哪些操作?
[root@centos7 testdir]# chmod o=wx /testdir/ [root@centos7 testdir]# ls -ld /testdir/ drwxr-x-wx. 3 root root 27 Aug 5 08:38 /testdir/ [root@centos7 testdir]# su xiaoming [xiaoming@centos7 testdir]$ ls ls: cannot open directory .: Permission denied [xiaoming@centos7 testdir]$ rm -rf file [xiaoming@centos7 testdir]$ rm -rf dir rm: cannot remove ‘dir/f1’: Permission denied rm: cannot remove ‘dir/f2’: Permission denied [xiaoming@centos7 testdir]$
從上訴實驗可知,不能ls查看,但可以刪除目錄中文件,不能刪除目錄中的目錄及文件
3、當用戶wang對/testdir 目錄無寫權限時,該目錄下的只讀文件file1是否可修改和刪除?
[root@centos7 testdir]# ls -ld /testdir/ drwxr-xr-x. 2 root root 17 Aug 5 13:05 /testdir/ [root@centos7 testdir]# su wang [wang@centos7 testdir]$ ls file [wang@centos7 testdir]$ rm -f file rm: cannot remove ‘file’: Permission denied [wang@centos7 testdir]$ echo aaaaa>>file bash: file: Permission denied [wang@centos7 testdir]$
從上訴實驗可知,不能刪除和修改此文件
4、復制/etc/fstab文件到/var/tmp下,設置文件所有者為 wang讀寫權限,所屬組為sysadmins組有讀寫權限,其他人無權限
[root@centos7 ~]# groupadd sysadmins [root@centos7 ~]# getent group sysadmins sysadmins:x:10012: [root@centos7 ~]# cp /etc/fstab /var/tmp/ [root@centos7 ~]# chown wang.sysadmins /var/tmp/fstab [root@centos7 ~]# ll /var/tmp/fstab -rw-r--r--. 1 wang sysadmins 507 Aug 5 13:11 /var/tmp/fstab [root@centos7 ~]#
5、誤刪除了用戶wang的家目錄,請重建并恢復該用戶家目錄 及相應的權限屬性
[root@centos7 ~]# cp /etc/skel/. /home/wang/ -r [root@centos7 ~]# cd /home/wang [root@centos7 wang]# ls -a . .. .bash_logout .bash_profile .bashrc .mozilla [root@centos7 wang]# cd ../ [root@centos7 home]# ls -ld ./wang drwxr-xr-x. 3 root root 74 Aug 5 13:13 ./wang [root@centos7 home]# chown -R wang.wang ./wang [root@centos7 home]# chmod 700 ./wang/ [root@centos7 home]# ll total 12 drwx------. 6 gentoo gentoo 4096 Aug 4 13:36 gentoo drwx------. 5 hadoop hadoop 4096 Aug 3 22:17 hadoop drwx------. 3 wang wang 74 Aug 5 13:13 wang drwx------. 5 xiaoming xiaoming 4096 Aug 5 09:54 xiaoming
6、設置user1,使之新建文件權限為rw——-
[root@centos7 ~]# useradd user1 [root@centos7 ~]# [root@centos7 ~]# su user1 [user1@centos7 root]$ cd [user1@centos7 ~]$ [user1@centos7 ~]$ vi ~/.bashrc [user1@centos7 ~]$ umask 0002 [user1@centos7 ~]$ . ~/.bashrc [user1@centos7 ~]$ umask 0066 [user1@centos7 ~]$ touch file.txt [user1@centos7 ~]$ ll file.txt -rw-------. 1 user1 user1 0 Aug 5 13:27 file.txt
7、設置/testdir/f1的權限,使user1用戶不可以讀寫執行,g1組可以讀寫
[root@centos7 testdir]# touch f1 [root@centos7 testdir]# ll total 0 -rw-r--r--. 1 root root 0 Aug 5 13:34 f1 -rw-r--r--. 1 root root 0 Aug 5 13:05 file [root@centos7 testdir]# setfacl -m u:user1:0,g:g1:rw /testdir/f1 [root@centos7 testdir]# getfactl /testdir/f1 bash: getfactl: command not found... [root@centos7 testdir]# 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--
8、/testdir/dir的權限,使新建文件自動具有acl權限:user1:rw,g1:—
[root@centos7 testdir]# mkdir dir [root@centos7 testdir]# ll total 4 drwxr-xr-x. 2 root root 6 Aug 5 13:39 dir -rw-rw-r--+ 1 root root 0 Aug 5 13:34 f1 -rw-r--r--. 1 root root 0 Aug 5 13:05 file [root@centos7 testdir]# setfacl -m d:u:user1:rw ./dir/ [root@centos7 testdir]# setfacl -m d:g:g1:0 ./dir/ [root@centos7 testdir]# getfacl ./dir/ # file: 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
9、在/data/testdir里創建的新文件自動屬于g1組,組g2的成員如: alice能對這些新文件有讀寫權限,
組g3的成員如: tom只能對新文件有讀權限,其它用戶(不屬于,g2,g3)不能訪問這個文件夾。
[root@centos7 testdir]# rm -rf /data/testdir/ [root@centos7 testdir]# [root@centos7 testdir]# mkdir -p /data/testdir/ [root@centos7 testdir]# ll /data/testdir/ total 0 [root@centos7 testdir]# ls -ld /data/testdir/ drwxr-xr-x. 2 root root 6 Aug 5 13:44 /data/testdir/ [root@centos7 testdir]# useradd alice [root@centos7 testdir]# useradd tom [root@centos7 testdir]# chmod g+s /data/testdir/ [root@centos7 testdir]# ls -ld /data/testdir/ drwxr-sr-x. 2 root root 6 Aug 5 13:44 /data/testdir/ [root@centos7 testdir]# chown .g1 /data/testdir/ [root@centos7 testdir]# ls -ld /data/testdir/ drwxr-sr-x. 2 root g1 6 Aug 5 13:44 /data/testdir/ [root@centos7 testdir]# gpasswd -g g2 -a alice Adding user alice to group g2 [root@centos7 testdir]# gpasswd -g g3 -a tom Adding user tom to group g3 [root@centos7 testdir]# setfacl -m d:g:g2:rw /data/testdir/ [root@centos7 testdir]# setfacl -m d:g:g3:r /data/testdir/ [root@centos7 testdir]# 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-
每天總結博客地址:http://purify.blog.51cto.com/
原創文章,作者:alren,如若轉載,請注明出處:http://www.www58058.com/29391