8.3作業

創建sysadmins組 

將user1 user2 user3 加入組中

將user3設置為管理員

用user3登錄,將user2從組中移除

設置sysadmins口令centos

設置user1在創建新文件時所屬組為sysadmins

刪除User1-3

刪除sysadmins

[root@localhost testdir]# groupadd sysadmins
[root@localhost testdir]# useradd -G sysadmins user1
[root@localhost testdir]# useradd -G sysadmins user2
[root@localhost testdir]# useradd -G sysadmins user3
[root@localhost testdir]# gpasswd -A user3 sysadmins
[root@localhost ~]# su - user3
[user3@localhost ~]$ gpasswd -d user2 sysadmins
Removing user user2 from group sysadmins
[user3@localhost ~]$ gpasswd sysadmins
Changing the password for group sysadmins
New Password: 
Re-enter new password: 
[root@localhost testdir]# groups user1
user1 : user1 sysadmins
[root@localhost testdir]# usermod -g sysadmins user1
[root@localhost testdir]# groups user1
user1 : sysadmins
[root@localhost testdir]# su - user1
Last login: Thu Aug  4 06:37:20 CST 2016 on pts/0
[user1@localhost ~]$ touch file1
[user1@localhost ~]$ ll file1
-rw-r--r-- 1 user1 sysadmins 0 Aug  4 06:39 file1
[root@localhost testdir]# userdel -r user1
userdel: group user1 not removed because it is not the primary group of user user1.
[root@localhost testdir]# userdel -r user2
[root@localhost testdir]# userdel -r user3
[root@localhost testdir]# groupdel sysadmins

在/data/testdir里創建的新文件自動屬于g1組,

組g2的成員如:alice能對這些新文件有讀寫權限

組g3的成員如:tom只能對新文件有讀權限,其他用戶(不屬于g1,g2,g3)不能訪問這個文件

[root@localhost data]# mkdir testdir
[root@localhost data]# groupadd g1
[root@localhost data]# groupadd g2
[root@localhost data]# groupadd g3
[root@localhost data]# chgrp g1 testdir
[root@localhost data]# chmod 2770 testdir
[root@localhost data]# ll
total 0
drwxrws--- 2 root g1 6 Aug  3 23:30 testdir
[root@localhost data]# setfacl -m g:g2:rwx testdir
[root@localhost data]# setfacl -m g:g3:rwx testdir
[root@localhost data]# setfacl -m d:g:g2:rwx testdir
[root@localhost data]# setfacl -m d:g:g3:r testdir
[root@localhost 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:rwx
default:group:g3:r--
default:mask::rwx
default:other::---

[root@localhost data]# useradd alice
[root@localhost data]# gpasswd -a alice g2
Adding user alice to group g2
[root@localhost data]# su - alice
[alice@localhost testdir]$ touch newfile1
[alice@localhost testdir]$ getfacl newfile1 
# file: newfile1
# owner: alice
# group: g1
user::rw-
group::rwx			#effective:rw-
group:g2:rwx			#effective:rw-
group:g3:r--
mask::rw-
other::---

三種權限rwx對文件個目錄的不同意義

文件

r:可使用文件查看類工具獲取其內容

w:可修改內容,但不能刪除文件本身

x:針對二進制程序或腳本,可以把此文件提請內核啟動為一個進程

X:本身沒有x權限,將不會增加

目錄:

r:可以查看文件列表,但不能訪問文件,不能cd進入目錄,也不能查看文件的元數據

w:可以創建或刪除目錄中文件,配合x

x:可以cd進入目錄,可以訪問目錄中文件

X:x等價

umask和 acl mask 的區別和聯系

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

suid可執行在文件上:啟動程序之后,其進程的屬主為原程序文件的屬主

sgid執行在文件上:啟動程序之后,其進程的屬主為原程序的屬組

sgid執行在目錄上:對此目錄有寫權限的用戶在此目錄中創建的文件所屬的組為此目錄的屬組

sticky作用在目錄上:只有文件的所有者或root可以刪除該文件

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

[root@localhost testdir]# useradd user1
[root@localhost testdir]# su - user1
[user1@localhost ~]$ umask
0002
[user1@localhost ~]$ umask 177
[user1@localhost ~]$ touch file2
[user1@localhost ~]$ ll file2
-rw------- 1 user1 user1 0 Aug  4 07:23 file2



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

g1組可以讀寫/testdir/dir的權限

使新建文件自動具有acl權限:user1:rw,g1:—

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

[root@localhost testdir]# touch f1
[root@localhost testdir]# mkdir dir
[root@localhost testdir]# ll
total 0
drwxr-xr-x 2 root root 6 Aug  4 11:12 dir
-rw-r--r-- 1 root root 0 Aug  4 11:12 f1
[root@localhost testdir]# chmod o-r f1
[root@localhost testdir]# useradd user1
[root@localhost testdir]# su - user1
[user1@localhost ~]$ cd /testdir/
[user1@localhost testdir]$ cat f1
cat: f1: Permission denied
[user1@localhost testdir]$ rm -rf f1
rm: cannot remove ‘f1’: Permission denied
[user1@localhost testdir]$ logout
[root@localhost testdir]# groupadd g1
[root@localhost testdir]# setfacl -m g:g1:rw dir 
[root@localhost testdir]# setfacl -m d:g:g1:0 dir 
[root@localhost testdir]# setfacl -m d:u:user1:rw dir
[root@localhost testdir]# getfacl dir
# file: dir
# owner: root
# group: root
user::rwx
group::r-x
group:g1:rw-
mask::rwx
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 testdir]# getfacl -R dir/ > file123
[root@localhost testdir]# setfacl -R -b dir
[root@localhost testdir]# getfacl dir
# file: dir
# owner: root
# group: root
user::rwx
group::r-x
other::r-x

[root@localhost testdir]# setfacl -R --restore=file123
[root@localhost testdir]# getfacl dir
# file: dir
# owner: root
# group: root
user::rwx
group::r-x
group:g1:rw-
mask::rwx
other::r-x
default:user::rwx
default:user:user1:rw-
default:group::r-x
default:group:g1:---
default:mask::rwx
default:other::r-x

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

(0)
DYWDYW
上一篇 2016-08-04
下一篇 2016-08-04

相關推薦

  • Function函數實例

    函數:function     把一段獨立功能的代碼當做一個整體,而后為之取一個名字,命令的代碼段,即為函數。 注意:     定義函數的代碼段不會自動執行,在調用時執行;所謂調用函數,在代碼中給定函數名即可     函數名出現的任何位置,…

    Linux干貨 2016-08-21
  • 第四周作業

    cp、grep、sueradd、chmod、vim命令的一些用法

    Linux干貨 2017-12-24
  • 如何恢復誤刪除的rpm包命令

    如何恢復誤刪除的rpm包命令 在linux學習過程中,我們會遇到各種各樣的問題,當然,如果能夠將遇到的問題一一解決也是非常開心的,因為在解決問題的過程中我們的專業技能也得到了很大的提升。最近的測試中遇到了一個平時很少接觸的問題:如何恢復誤刪除的rpm包命令。所以覺得有必要寫下來,以防止下次出現類似的問題而不會解決。 首先模擬卸載rpm rpm -e &#82…

    2017-08-26
  • AWK基礎用法

    AWK: print 例子:給沒個/etc/passwd下的用戶都打招呼hello 答案: awk ‘{print “hello:”$1}’ /etc/passwd 內建變量 FS : 輸入分隔符 OFS: 輸出分隔符 RS : 行輸入分隔符 ORS: 行輸出分割符 NF : 字段數 NR : 行號數 FNR: 每個文件的行號數 ARGC: 參數個數 ARG…

    Linux干貨 2017-05-22
  • 磁盤管理

    磁盤管理 本文將按順序以實例演示磁盤管理的所有操作,讓我們開始吧! 一,磁盤的添加 ① 先來查看linux系統總共有幾個磁盤,由圖可知是兩個,分別是sda,sdb。我們再加一個,按照磁盤命名順序,應是sdc,他們都在/dev目錄下。 補充: 1,磁盤命名規則: 不同磁盤,按照a-z依次標識,如sda,sdb,sdc 同一磁盤的不同分區,按照1,2,&#823…

    2017-08-19
  • 博客開始的地方

    來北京挺長時間了,一直都在瞎忙,特別想找個地逛逛,約朋友一起去,結果人家只喜歡吃飯,逛街,來北京瞎逛過兩次,第一次是面試路過潘家園,然后進去逛了半天,看各種各樣的老古董,當然最多的還是手串,那種核桃,當然還是看到了好多好多有意思的東西,比如下面的小和尚和老和尚,小和尚光著頭感覺特別可愛,老和尚還賣萌, 當然還有下面這個關老爺,他的肚子為什么被雕刻的那么大,難…

    2018-03-26
欧美性久久久久