創建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