M20 – 1- 第三周(2):課堂練習與作業

課堂練習:

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

[root@centos6 ~]# groupadd g1
[root@centos6 ~]# groupadd g2
[root@centos6 ~]# groupadd g3
[root@centos6 ~]# useradd -G g2 alice
[root@centos6 ~]# useradd -G g3 tom
[root@centos6 ~]# id alice
uid=501(alice) gid=504(alice) groups=504(alice),502(g2)
[root@centos6 ~]# id tom
uid=502(tom) gid=505(tom) groups=505(tom),503(g3)
[root@centos6 ~]# mkdir -p /data/testdir
[root@centos6 ~]# cd /data/
[root@centos6 data]# ll
total 4
drwxr-xr-x. 2 root root 4096 Aug  6 19:06 testdir
[root@centos6 data]# chgrp g1 testdir/
[root@centos6 data]# chmod g+sw,o= testdir/
[root@centos6 data]# ll
total 4
drwxrws---. 2 root g1 4096 Aug  6 19:06 testdir
[root@centos6 data]# setfacl -m g:g2:rwx,g:g3:rwx testdir/
[root@centos6 data]# setfacl -m d:g:g2:rw,d:g:g3:r testdir/
[root@centos6 data]# getfacl testdir/
# file: testdir/
# owner: root
# group: g1
# flags: -s-
user::rwx
group::rwx
group:g2:rwx
group:g3:rwx
mask::rwx
other::---
default:user::rwx
default:group::rwx
default:group:g2:rw-
default:group:g3:r--
default:mask::rwx
default:other::---

[root@centos6 data]#

作業:

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

[user1@centos6 ~]$ echo "umask 0066" >> .bashrc 
[user1@centos6 ~]$ . .bashrc
[user1@centos6 ~]$ umask
0066
[user1@centos6 ~]$ touch file1
[user1@centos6 ~]$ ls -l file1 
-rw-------. 1 user1 user1 0 Aug  6 19:16 file1
[user1@centos6 ~]$

2、設置/testdir/f1的權限,使user1用戶不可以讀寫執行,g1組可以讀寫/testdir/dir的權限,使新建文件自動具有acl權限:user1:rw,g1:—,備份/testdir目錄中所有文件的ACL,清除/testdir的所有ACL權限,并利用備份還原

[root@centos6 testdir]# ls -ld .
drwxr-xr-x. 2 root root 4096 Aug  6 20:25 .
[root@centos6 testdir]# mkdir -p /testdir/dir/
[root@centos6 testdir]# touch f1
[root@centos6 testdir]# setfacl -m u:user1:0,g:g1:rw /testdir/f1
[root@centos6 testdir]# setfacl -m d:u:user1:rw,d:g:g1:0 /testdir/dir/
[root@centos6 testdir]# getfacl -R * > /root/acl.txt
[root@centos6 testdir]# setfacl -R --set-file=/root/acl.txt /testdir/dir

3、三種權限rwx對文件和目錄的不同意義

文件的權限意義

r: 可使用文件查看類工具獲取其內容;
w: 可修改其內容;
x: 可以把此文件提請內核啟動為一個進程

目錄的權限意義

r: 可以使用ls查看此目錄中文件列表;
w: 可在此目錄中創建文件,也可刪除此目錄中的文件;
x: 可以使用ls -l查看此目錄中文件列表,可以cd進入此目錄;

4、umask和acl mask 的區別和聯系

umask:從目錄或文件上屏蔽掉最大權限相應的位,從而得出默認權限
acl:為指定用戶或用戶組添加權限
mask:控制acl列表中用戶的最高權限

5、三種特殊權限的應用場景和作用

SUID

作用:任何一個可執行程序文件能不能啟動為進程:取決發起者對程序文件是否擁有執行權限,啟動為進程之后,其進程的屬主為原程序文件的屬主
場景:啟動為進程之后,其進程的屬主為原程序文件的屬主,SUID只對二進制可執行程序有效,SUID設置在目錄上無意義

SGID

作用:任何一個可執行程序文件能不能啟動為進程:取決發起者對程序文件是否擁有執行權限;啟動為進程之后,其進程的屬主為原程序文件的屬組
場景:默認情況下,用戶創建文件時,其屬組為此用戶所屬的主組;一旦某目錄被設定了SGID,則對此目錄有寫權限的用戶在此目錄中創建的文件所屬的組為此目錄的屬組;通常用于創建一個
協作目錄

SGID

作用:具有寫權限的目錄通常用戶可以刪除該目錄中的任何文件,無論該文件的權限或擁有權
場景:在目錄設置Sticky 位,只有文件的所有者或root可以刪除該文件;sticky 設置在文件上無意義

原創文章,作者:Aleen,如若轉載,請注明出處:http://www.www58058.com/30181

(0)
AleenAleen
上一篇 2016-08-08
下一篇 2016-08-08

相關推薦

  • 馬哥教育網絡班19期+第九周課程練習

    1、寫一個腳本,判斷當前系統上所有用戶的shell是否為可登錄shell(即用戶的shell不是/sbin/nologin);分別這兩類用戶的個數;通過字符串比較來實現; 2、寫一個腳本     (1) 獲取當前主機的主機名,保存于hostname變量中;     (2) 判斷此變量的值是否為localhost,如果是…

    2016-07-04
  • 馬哥教育網絡班20期+第3周課程練習

    1、列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄多次,則只顯示一次即可。    w | grep "^root\>" |sort -u   2、取出最后登錄到當前系統的用戶的相關信息。    who |   3、取出當前系統上被用戶當作…

    Linux干貨 2016-06-26
  • shell腳本基礎

    shell腳本編程基礎 1、基本格式 首先在編寫shell的開始要聲明一下該shell所用的腳本類型,我們也稱為shebang機制 eg: #!/bin/bash # Description … 2、bash中的變量的種類 (1)、本地變量 生效范圍: 當前shell進程,對當前shell之外的進程及子進程均無效 (2)、環境變量 生效范圍: 當前she…

    Linux干貨 2017-08-04
  • 利用keepalived實現主/從和主/主模式的高性能負載均衡集群

    要求: 1、使用nginx的反向代理功能實現負載均衡 2、keepalived實現高可用 ???????第一組的虛擬地址為172.16.1.100 ????????????D設備的優先級高 ???????第二組的虛擬地址為172.16.1.110 ????????????E設備的優先級高 3、分別實現主/從和主/主兩種配置 集群拓撲: ? ? ? 第一種:主…

    2017-06-25
  • shell進階之循環

    循環執行,將某代碼段重復運行多次

    重復運行多少次:

    循環次數事先已知

    循環次數事先未知

    有進入條件和退出條件

    for, while, until

    Linux干貨 2017-12-24
  • iptables基本知識

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

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