M20-1權限作業

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

(0)
alrenalren
上一篇 2016-08-05 16:09
下一篇 2016-08-05 16:09

相關推薦

  • Linux基礎知識(四)

    本文主要講述:Linux上用戶和組的基本管理,具體包括一下內容 1、復制/etc/skel目錄到/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。 2、編輯/etc/group文件,添加組hadoop。 3、手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id…

    Linux干貨 2016-10-16
  • 文件的權限詳解(一)

    文件的權限 修改文件的屬主和屬組 chown 功能:更改屬主命令,同時也能更改屬組用法:   chown  選項  [屬主名][:屬組名]  文件名  (分隔符改成.也行) chown  選項   參考的文件=要更改的文件 chown [OPTION]… –reference=R…

    Linux干貨 2016-08-04
  • Centos6.5上搭建openvpn

    前言     為了方便遠程辦公時訪問公司的內部系統,如:svn、OA、wiki、禪道等等;通通在防火墻上做了端口映射。發現有時也不好用,所有開始弄OPENVPN。 openvpn簡介     官方網站:https://openvpn.net 打不開請爬墻   &nbsp…

    Linux干貨 2016-02-14
  • 文件查找命令(find、locate)

    在文件系統上查找符合條件的文件: 實現工具:locate, find locate: 依賴于事先構建好的索引庫; 系統自動實現(周期性任務); 手動更新數據庫(updatedb); 工作特性: 查找速度快; 模糊查找; 非實時查找; locate [OPTION]… PATTERN… -b:只匹配路徑中的基名; -c:統計出共有多少個符合條件的文件;…

    Linux干貨 2016-11-06
  • N28-第四周

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限。
    2、編輯/etc/group文件,添加組hadoop。
    3、手動編輯/etc/passwd文件新增一行,添加用戶hadoop,其基本組ID為hadoop組的id號;其家目錄為/home/hadoop。
    4、復制/etc/skel目錄為/home/hadoop,要求修改hadoop目錄的屬組和其它用戶沒有任何訪問權限。
    5、修改/home/hadoop目錄及其內部所有文件的屬主為hadoop,屬組為hadoop。
    6、顯示/proc/meminfo文件中以大寫或小寫S開頭的行;用兩種方式;
    7、顯示/etc/passwd文件中其默認shell為非/sbin/nologin的用戶;
    8、顯示/etc/passwd文件中其默認shell為/bin/bash的用戶;
    9、找出/etc/passwd文件中的一位數或兩位數;
    10、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行;
    11、顯示/etc/rc.d/rc.sysinit文件中以#開頭,后面跟至少一個空白字符,而后又有至少一個非空白字符的行;
    12、打出netstat -tan命令執行結果中以‘LISTEN’,后或跟空白字符結尾的行;
    13、添加用戶bash, testbash, basher, nologin (此一個用戶的shell為/sbin/nologin),而后找出當前系統上其用戶名和默認shell相同的用戶的信息;

    2017-12-30
  • linux的內建命令和外部命令

    摘要:    Linux命令有內部命令(內建命令)和外部命令之分,內部命令和外部命令功能基本相同,但是其工作機制相差很大。本文就內建命令和外部命令做一下介紹。 一、內部命令(內建命令)    內部命令,實際上是shell程序的一部分,其中包含的是一些比較簡單的linux系統命令,這些命令由shell程序識別并在shel…

    Linux干貨 2016-10-18
欧美性久久久久