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 14:42
下一篇 2016-08-04 17:40

相關推薦

  • rsync+inotify實時同步備份數據

    rsync同步 rsync+inotify實時同步備份數據 軟件簡介: rsync命令簡介: rsync命令是一個遠程數據同步工具,可通過LAN/WAN快速同步多臺主機間的文件。rsync使用所謂的“rsync算法”來使本地和遠程兩個主機之間的文件達到同步,這個算法只傳送兩個文件的不同部分,而不是每次都整份傳送,因此速度相當快。 rsync是一個功能非常強大…

    Linux干貨 2016-10-28
  • 使用mysql-mmm實現高可用mysql讀寫分離

    MMM介紹:  MMM全稱為Multi-Master Replication Manager for MySQL,即為主主復制管理器;根據MMM官網介紹,其工作原理類似于lvs,都是利用vip地址;但lvs只有一個組件便可以正常工作,而MMM則使用三個組件,分別是mysql-mmm、mysql-mmm-agent、mysql-mmm-monitor…

    Linux干貨 2015-08-04
  • NET25第8周作業

    1、寫一個腳本,使用ping命令探測172.16.250.1-172.16.250.254之間的所有主機的在線狀態;     在線的主機使用綠色顯示;     不在線的主使用紅色顯示; #!/bin/bashtrap “echo ‘crtrl+c’;exi…

    Linux干貨 2017-03-15
  • 馬哥教育網絡班21期-第九周課程練習

    1、寫一個腳本,判斷當前系統上所有用戶的shell是否為可登錄shell(即用戶的shell不是/sbin/nologin);分別這兩類用戶的個數;通過字符串比較來實現; #!/bin/bash m=0 n=0 for i in `awk -F: '{print $NF}'&nb…

    Linux干貨 2016-09-15
  • 硬鏈接與軟鏈接的聯系與區別

    硬鏈接與軟鏈接的聯系與區別 我們知道文件都有文件名與數據,這在 Linux 上被分成兩個部分:用戶數據 (user data) 與元數據 (metadata)。用戶數據,即文件數據塊 (data block),數據塊是記錄文件真實內容的地方;而元數據則是文件的附加屬性,如文件大小、創建時間、所有者等信息。在 Linux 中,元數據中的 inode 號(ino…

    Linux干貨 2016-10-23
  • 網絡第21期第七周作業

    1、創建一個10G分區,并格式為ext4文件系統;    (1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl; [root@localhost ~]# fdisk /dev/sdb WARNING: DOS-compatible m…

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