7月24日 上課練習和作業

  • 文件權限
    ?1、當用戶xiaoming對/testdir 目錄無執行權限時,意味著無法做哪些操作?
    無法進入該目錄
    ?2、當用戶xiaoqiang對/testdir 目錄無讀權限時,意味著無法做哪些操作?
    無法看目錄內的文件列表
    ?3、當用戶wangcai 對/testdir 目錄無寫權限時,該目錄下的只讀文件file1是否可修改和刪除?
    不可以
    ?4、當用戶wangcai 對/testdir 目錄有寫和執行權限時,該目錄下的只讀文件file1是否可修改和刪除?
    不可以修改但可以刪除
    ?5、復制/etc/fstab文件到/app/tmp下,設置文件所有者為zhang讀寫權限,所屬組為admins組有讀寫權限,其他人無權限
[root@centos6 app]#cp /etc/fstab ./tmp
[root@centos6 app]#ll
total 28
drwxr--r--. 2 zhang root 4096 Jul 25 09:25 dir1
-rw-rw-r--+ 1 root  root   51 Jul 25 08:30 f1
-rw-rw-r--+ 1 root  root   27 Jul 25 08:32 f2
-rw-r--r--. 1 root  root   19 Jul 25 08:16 f3
-rw-r--r--. 1 root  root  899 Jul 25 09:28 tmp
[root@centos6 app]#chown zhang tmp
[root@centos6 app]#chgrp admins tmp
[root@centos6 app]#ll
total 28
drwxr--r--. 2 zhang root   4096 Jul 25 09:25 dir1
-rw-rw-r--+ 1 root  root     51 Jul 25 08:30 f1
-rw-rw-r--+ 1 root  root     27 Jul 25 08:32 f2
-rw-r--r--. 1 root  root     19 Jul 25 08:16 f3
-rw-r--r--. 1 zhang admins  899 Jul 25 09:28 tmp
[root@centos6 app]#chmod u=rw,g=rw,o= tmp
[root@centos6 app]#ll
total 28
drwxr--r--. 2 zhang root   4096 Jul 25 09:25 dir1
-rw-rw-r--+ 1 root  root     51 Jul 25 08:30 f1
-rw-rw-r--+ 1 root  root     27 Jul 25 08:32 f2
-rw-r--r--. 1 root  root     19 Jul 25 08:16 f3
-rw-rw----. 1 zhang admins  899 Jul 25 09:28 tmp

?6、誤刪除了用戶harry的家目錄,請重建并恢復該用戶家目錄及相應的權限屬性

[root@centos6 home]#ls
dufu  gentoo  harry  libai  natasha  tom  zhang  zhaoritian
[root@centos6 home]#rm -rf harry
[root@centos6 home]#ls
dufu  gentoo  libai  natasha  tom  zhang  zhaoritian
[root@centos6 home]#cp -r /etc/skel  /home/harry  ---第一步
[root@centos6 home]#ls
dufu  gentoo  harry  libai  natasha  tom  zhang  zhaoritian
[root@centos6 home]#chown -R harry harry  ---第二步
[root@centos6 home]#chgrp -R harry harry
[root@centos6 home]#ll
total 32
drwx------. 2 dufu       dufu       4096 Jul 22 14:05 dufu
drwx------. 4 gentoo     gentoo     4096 Jul 24 10:17 gentoo
drwxr-xr-x. 4 harry      harry      4096 Jul 25 09:39 harry
drwx------. 2 libai      libai      4096 Jul 22 14:05 libai
drwx------. 4 natasha    natasha    4096 Jul 22 15:16 natasha
drwx------. 4 tom        tom        4096 Jul 22 10:50 tom
drwx------. 4 zhang      zhang      4096 Jul 25 09:25 zhang
drwx------. 2 zhaoritian zhaoritian 4096 Jul 22 14:08 zhaoritian
[root@centos6 home]#chmod 0700 harry   --第三步
[root@centos6 home]#ll
total 32
drwx------. 2 dufu       dufu       4096 Jul 22 14:05 dufu
drwx------. 4 gentoo     gentoo     4096 Jul 24 10:17 gentoo
drwx------. 4 harry      harry      4096 Jul 25 09:39 harry
drwx------. 2 libai      libai      4096 Jul 22 14:05 libai
drwx------. 4 natasha    natasha    4096 Jul 22 15:16 natasha
drwx------. 4 tom        tom        4096 Jul 22 10:50 tom
drwx------. 4 zhang      zhang      4096 Jul 25 09:25 zhang
drwx------. 2 zhaoritian zhaoritian 4096 Jul 22 14:08 zhaoritian
  • ACL 訪問控制列表
    1、在/app/dir里創建的新文件自動屬于g1組,組g2的成員如:alice能對這些新文件有讀寫權限,組g3的成員如:tom只能對新文件有讀權限,其它用戶(不屬于g1,g2,g3)不能訪問這個文件夾。
[root@centos6 app]#mkdir dir
[root@centos6 app]#ll
total 4
drwxr-xr-x. 2 root root 4096 Jul 25 09:53 dir
[root@centos6 app]#groupadd g1
[root@centos6 app]#chgrp g1 dir
[root@centos6 app]#ll
total 4
drwxr-xr-x. 2 root g1 4096 Jul 25 09:53 dir
[root@centos6 app]#chmod g+s dir
[root@centos6 app]#ll
total 4
drwxr-sr-x. 2 root g1 4096 Jul 25 09:53 dir
[root@centos6 app]#groupadd g2
[root@centos6 app]#groupadd g3
[root@centos6 app]#useradd -g g2 alice
[root@centos6 app]#id alice
uid=518(alice) gid=518(g2) groups=518(g2)
[root@centos6 app]#id tom
uid=504(tom) gid=505(tom) groups=505(tom),500(zhang),501(gentoo),504(harry)
[root@centos6 app]#gpasswd -a tom g3
Adding user tom to group g3
[root@centos6 app]#id tom
uid=504(tom) gid=505(tom) groups=505(tom),500(zhang),501(gentoo),504(harry),519(g3)
[root@centos6 app]#setfacl -Rm d:g:g2:rwx dir
[root@centos6 app]#setfacl -Rm d:g:g3:rx dir
[root@centos6 app]#ll
total 8
drwxr-sr-x+ 2 root g1 4096 Jul 25 09:53 dir
[root@centos6 app]#chmod u=rwx,g=rwx,o= dir
[root@centos6 app]#ll
total 8
drwxrws---+ 2 root g1 4096 Jul 25 09:53 dir

?2、備份/testdir/dir里所有文件的ACL權限到/root/acl.txt中,清除/testdir/dir中所有ACL權限,最后還原ACL權限

[root@centos6 app]#getfacl -R dir/>/root/acl.txt   ---備份acl權限
[root@centos6 ~]#setfacl -Rb /app/dir/ ---清除acl權限
[root@centos6 app]#setfacl --set-file=/root/acl.txt /app/dir/ ---還原
  • 文本處理工具
    ?1、找出ifconfig “網卡名”命令結果中本機的IPv4地址
[root@centos6 app]#ifconfig eth2|head -2|tail -1|tr -s " "|cut -d " " -f3|cut -d: -f2
192.168.25.142

?2、查出分區空間使用率的最大百分比值

[root@centos6 app]#df|grep ^/dev/sd|tr -s " " "%"|cut -d "%" -f5|sort -nr|head -n1
10

?3、查出用戶UID最大值的用戶名、UID及shell類型

[root@centos6 app]#cat /etc/passwd|sort -t: -k3 -n|tail -n1|cut -d: -f1,3,7
nfsnobody:65534:/sbin/nologin

?4、查出/tmp的權限,以數字方式顯示

[root@centos6 app]#stat /tmp |head -4|tail -1|cut -d "(" -f2|cut -d "/" -f1
1777

?5、查看access_log日志文件中,遠程主機IP連接數排名前10名的IP

[root@centos6 app]#cat access_log |cut -d " " -f1|sort|uniq -c|sort -nr|head -n10
  10231 192.168.25.128
     42 ::1
     33 192.168.25.1
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容