8.3-特殊權限(作業篇)

1. 在/data/testdir里創建的新文件自動屬于g1組,組g2的成員如: alice能對這些新文件有讀寫權限,
組g3的成員如: tom只能對新文件有讀權限,其它用戶(不屬于,g2,g3)不能訪問這個文件夾

root@localhost ~]# mkdir -p /data/testdir
[root@localhost ~]# groupadd g1
[root@localhost ~]# groupadd g2
[root@localhost ~]# groupadd g3
[root@localhost ~]# ll /data/testdir/ -d
drwxr-xr-x. 2 root root 4096 7月  21 07:01 /data/testdir/
[root@localhost ~]# chmod g+s /data/testdir
[root@localhost ~]# ll /data/testdir/ -d
drwxr-sr-x. 2 root root 4096 7月  21 07:01 /data/testdir/
[root@localhost ~]# chown :g1 /data/testdir
[root@localhost ~]# ll /data/testdir/ -d
drwxr-sr-x. 2 root g1 4096 7月  21 07:01 /data/testdir/
[root@localhost ~]# useradd alice
[root@localhost ~]# gpasswd -a alice g2
正在將用戶“alice”加入到“g2”組中
[root@localhost ~]# useradd tom
[root@localhost ~]# gpasswd -a tom g3
正在將用戶“tom”加入到“g3”組中
[root@localhost ~]# setfacl -m d:g:g2:rw /data/testdir/
[root@localhost ~]# setfacl -m d:g:g3:r /data/testdir/
[root@localhost ~]# 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-x
                    
[root@localhost ~]# chmod o= /data/testdir/
[root@localhost ~]# ll /data/testdir/ -d
drwxr-s---+ 2 root g1 4096 7月  21 07:01 /data/testdir/
[root@localhost ~]# setfacl -m g:g2:rwx /data/testdir/
[root@localhost ~]# setfacl -m g:g3:rwx /data/testdir/
創建新文件
touch /data/testdir/f2
g2組alice,對新文件f2可讀寫
[root@localhost ~]# su - alice
[alice@localhost ~]$ cat /data/testdir/f2
[alice@localhost ~]$ echo "aaa" > /data/testdir/f2
[alice@localhost ~]$ cat /data/testdir/f2
aaa
g3組:tom,對新文件只讀
[root@localhost ~]# su - tom
[tom@localhost testdir]$ cat ./f2
[tom@localhost testdir]$ echo "a" >f2
-bash: f2: 權限不夠
其他用戶:user1,不能訪問目錄
[root@localhost ~]# su - user1
[user1@localhost testdir]$ cd /data/testdir/
-bash: cd: /data/testdir/: 權限不夠

2.設置user1,使之新建文件權限為rw——-

[user1@localhost ~]$ umask 066
[user1@localhost ~]$ touch b
[user1@localhost ~]$ ll b
-rw-------. 1 user1 user1 0 7月  21 04:23 b

3.設置/testdir/f1的權限,使user1用戶不可以讀寫執行,g1組可以讀寫

  [root@localhost /]# setfacl -m u:user1:---  /testdir/f1 
  [root@localhost /]# getfacl /testdir/f1
  getfacl: Removing leading '/' from absolute path names
  # file: testdir/f1
  # owner: root
  # group: root
  user::rw-
  user:user1:---
  group::r--
  mask::r--
  other::r--
  [root@localhost /]# groupadd g1
  [root@localhost /]# setfacl -m g:g1:rw /testdir/f1 
  [root@localhost /]# 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--

4./testdir/dir的權限,使新建文件自動具有acl權限:user1:rw,g1:—

[root@localhost /]# mkdir testdir/dir
[root@localhost /]# setfacl -m d:u:user1:rw testdir/dir
[root@localhost /]# setfacl -m d:g:g1:--- testdir/dir
[root@localhost /]# getfacl testdir/dir
# file: testdir/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
[root@localhost ~]# chmod o+w  /testdir/dir/
[user1@localhost dir]$ touch /testdir/dir/f2
[user1@localhost dir]$ ll ./f2 
-rw-rw-r--+ 1 user1 user1 0 7月  21 05:42 ./f2

5.備份/testdir目錄中所有文件的ACL,清除/testdir的所有ACL權限,并利用備份還原

[root@localhost ~]# getfacl /testdir/
getfacl: Removing leading '/' from absolute path names
# file: testdir/
# owner: root
# group: g1
# flags: -s-
user::rwx
group::r-x
group:g2:rwx
group:g3:rwx
mask::rwx
other::---
default:user::rwx
default:group::r-x
default:group:g2:rw-
default:group:g3:r--
default:mask::rwx
default:other::r-x

[root@localhost ~]# getfacl -R /testdir/ > /tmp/acl.txt

[root@localhost ~]# setfacl -b /testdir/
[root@localhost ~]# getfacl /testdir/
getfacl: Removing leading '/' from absolute path names
# file: testdir/
# owner: root
# group: g1
# flags: -s-
user::rwx
group::r-x
other::---

[root@localhost ~]# setfacl -R --set-file=/tmp/acl.txt /testdir/
[root@localhost ~]# getfacl /testdir/
getfacl: Removing leading '/' from absolute path names
# file: testdir/
# owner: root
# group: g1
# flags: -s-
user::rw-
group::r-x   #effective:r--
group:g2:rw-
group:g3:r--
mask::rw-
other::r--
default:user::rwx
default:group::r-x
default:group:g2:rw-
default:group:g3:r--
default:mask::rwx
default:other::r-x

6.當用戶xiaoming對/testdir 目錄無執行權限時,意味著無法做哪些操作?

[root@localhost ~]# ll /testdir/ -d
drwxr-xrw-. 2 root root 4096 7月  21 10:07 /testdir/
[xiaoming@localhost /]$ cd testdir/
-bash: cd: testdir/: 權限不夠
[xiaoming@localhost /]$ ls /testdir/
ls: 無法訪問/testdir/aaa: 權限不夠
aaa
[xiaoming@localhost /]$ ls -l /testdir/
ls: 無法訪問/testdir/aaa: 權限不夠
總用量 0
-????????? ? ? ? ?            ? aaa
不能ls -l 此目錄
不能cd進此目錄

7.當用戶xiaoqiang對/testdir 目錄無讀權限時,意味著無法做哪些操作?

[root@localhost /]# su - xiaoqiang
[xiaoqiang@localhost ~]$ cd /testdir/
[xiaoqiang@localhost testdir]$ ls
ls: 無法打開目錄.: 權限不夠
[xiaoqiang@localhost testdir]$ ll
ls: 無法打開目錄.: 權限不夠
[xiaoqiang@localhost testdir]$ rm -rf aaa
不能使用ls查看目錄下文件

8.當用戶wangcai 對/testdir 目錄無寫權限時,該目錄下的只讀文件file1是否可修改和刪除?

[root@localhost testdir]# ll file1 
-rwxr-xr--. 1 root root 0 7月  21 10:30 file1
[root@localhost testdir]# su - wangcai
[wangcai@localhost ~]$ cd /testdir/
[wangcai@localhost testdir]$ ls
file1
[wangcai@localhost testdir]$ rm file1 
rm:是否刪除有寫保護的普通空文件 "file1"?y
rm: 無法刪除"file1": 權限不夠
[wangcai@localhost testdir]$ echo "a"> file1 
-bash: file1: 權限不夠
不能修改,不能刪除

9.復制/etc/fstab文件到/var/tmp下,設置文件所有者為wangcai讀寫權限,所屬組為sysadmins組有讀寫權限,其他人無權限

[root@localhost ~]# cp /etc/fstab /var/tmp/
[root@localhost ~]# chown wangcai:sysadmins /var/tmp/fatsb
[root@localhost ~]# chmod 660 /var/tmp/fatab
[root@localhost ~]# ll /var/tmp/fstab
總用量 4
-rw-rw----. 1 root root 805 7月  21 10:33 fstab

10.誤刪除了用戶wangcai的家目錄,請重建并恢復該用戶家目錄及相應的權限屬性

cp /etc/skel/ /home/wangcai
chown wangcai:wangcai /home/wangcai
chmod 600 /home/wangcai



原創文章,作者:M20-1--孔祥文,如若轉載,請注明出處:http://www.www58058.com/28846

(1)
M20-1--孔祥文M20-1--孔祥文
上一篇 2016-08-04 21:40
下一篇 2016-08-04 21:40

相關推薦

  • LVM: Logical Volume Manager 邏輯卷管理

      一、LVM介紹         LVM: Logical Volume Manager, Version: 2             …

    Linux干貨 2016-09-19
  • 文件查找工具之——find

        前言:Linux一切皆文件,在linux的系統中如果我們需要找到所需的文件,除了一步一步慢慢找,還有一種辦法就是要使用Linux中查找文件工具命令,能讓我們很快定位到我們所需的文件。所以我們必須要學好文件查找工具 一、首先我們先要了解文本搜索和文件查找的區別     文本…

    Linux干貨 2015-07-06
  • 自己做一個CA

    構建CA服務器    CA配置文件位置:        /etc/pki/tls/openssl.cfg           &n…

    Linux干貨 2017-04-11
  • 學習宣言

    已經虛度了第一個關鍵的10年,不能再失去下一個10年,3年內年薪20w,5年內年薪30w。

    Linux干貨 2016-12-26
  • 第十七周作業

    1、結合圖形描述LVS的工作原理; 工作方式: LVS由前端的負載均衡器(Load Balancer,LB)和后端的真實服務器(Real Server,RS)群組成。RS間可通過局域網或廣域網連接。LVS的這種結構對用戶是透明的,用戶只能看見一臺作為LB的虛擬服務器(Virtual Server),而看不到提供服務的RS群。當用戶的請求發往虛擬服務器,LB根…

    2017-05-27
  • iptables基本知識

    1)Linux下的防火墻概念 a、一般談到Linux下的防火墻,我們都會首先想到iptables,其實更確切的叫法應該是Netfilter/iptables,iptables和Netfilter其實是存在差別的。 b、盡管它們經常被用來相互替換使用,Netfilter是用來實現Linux內核中防火墻的Linux內核空間程序代碼段,它要么被直接編譯進內核,要么…

    Linux干貨 2016-07-16
欧美性久久久久