在/data/testdir里創建的新文件自動屬于g1組,組g2的成員如:alice能對這些新文件有讀寫權限,組g3的成員如:tom只能對新文件有讀權限,其它用戶(不屬于g1,g2,g3)不能訪問這個文件夾。
[root@localhost ~]# groupadd g1
[root@localhost ~]# groupadd g2
[root@localhost ~]# groupadd g3
[root@localhost ~]# mkdir -p /data/testdir
[root@localhost ~]# chown -R :g1 /data/testdir
[root@localhost ~]# ll -d /data/testdir
drwxr-xr-x. 2 root g1 6 8月 2 19:48 /data/testdir
[root@localhost ~]# chmod 770 /data/testdir
[root@localhost ~]# ll -d /data/testdir
drwxrwx—. 2 root g1 6 8月 2 19:48 /data/testdir
[root@localhost ~]# useradd -G g2 alice
[root@localhost ~]# useradd -G g3 tom
[root@localhost ~]# setfacl -m g:g2:rw /data/testdir
[root@localhost ~]# setfacl -m g:g3:r /data/testdir
[root@localhost ~]# getfacl /data/testdir
getfacl: Removing leading '/' from absolute path names
# file: data/testdir
# owner: root
# group: g1
user::rwx
group::rwx
group:g2:rw-
group:g3:r–
mask::rwx
other::—
[root@localhost ~]# ll -d /data/testdir/
drwxrwx—+ 2 root g1 6 8月 2 19:48 /data/testdir/
創建組sales,gid 3000,passwd:centos,sales admins:user2
將用戶user1,user2,user3加入到sales輔助組
希望user1 創建新文件 默認的所屬組為sales
user2將用戶user3從sales組移除
刪除sales,user1,user2
[root@localhost ~]# groupadd -g 3000 sales
[root@localhost ~]# gpasswd sales
正在修改 sales 組的密碼
新密碼:
請重新輸入新密碼:
[root@localhost ~]# useradd -G sales user2
[root@localhost ~]# gpasswd -A user2 sales
[root@localhost ~]# useradd -G sales user1
[root@localhost ~]# useradd -G sales user3
[root@localhost ~]# usermod -g sales user1
[root@localhost ~]# su – user1
[user1@localhost ~]$ touch 1.txt
[user1@localhost ~]$ ll 1.txt
-rw-r–r–. 1 user1 sales 0 8月 2 20:09 1.txt
[user1@localhost ~]$ exit
登出
[root@localhost ~]# su – user2
[user2@localhost ~]$ gpasswd -d user3 sales
正在將用戶“user3”從“sales”組中刪除
[user2@localhost ~]$ exit
登出
[root@localhost ~]# userdel -r user1
userdel:組“user1”沒有移除,因為它不是用戶 user1 的主組
[root@localhost ~]# userdel -r user2
[root@localhost ~]# groupdel sales
原創文章,作者:zebra930,如若轉載,請注明出處:http://www.www58058.com/27631