groupadd 增加群組。
groupmod group 相關參數的修改。
groupdel 刪除群組。
gpasswd 群組密碼管理。
[root@linux ~]# groupadd [-g gid] [-r]
參數:
-g :後面接某個特定的 GID ,用來直接給予某個 GID。
-r :建立系統群組。與 /etc/login.defs 內的 GID_MIN 有關。
[root@dywOffice ~]# groupadd -g 55 testing
[root@dywOffice ~]# grep testing /etc/group /etc/gshadow
/etc/group:testing:x:55:
/etc/gshadow:testing:!::
[root@linux ~]# groupmod [-g gid] [-n group_name]
參數:
-g :修改既有的 GID 數字;
-n :修改既有的群組名稱。
[root@dywOffice ~]# groupmod -g 113 -n group3 testing
[root@dywOffice ~]# grep group3 /etc/group /etc/gshadow
/etc/group:group3:x:113:
/etc/gshadow:group3:!:: <= ! 預設是私有群組,並無法使用 newgrp 來登入
[root@dywOffice ~]# groupdel group3
[root@dywOffice ~]# groupdel test1
groupdel: cannot remove user's primary group.
#必須要確認 /etc/passwd 內的帳號沒有任何用戶使用該群組作為 initial group
[root@dywOffice ~]# grep test1 /etc/passwd
test1:x:511:511::/home/test1:/bin/bash
[root@dywOffice ~]# userdel -r test1
[root@dywOffice ~]# groupdel test1
關於系統管理員(root)做的動作:
[root@linux ~]# gpasswd groupname
[root@linux ~]# gpasswd [-A user1,...] [-M user3,user4...] groupname
[root@linux ~]# gpasswd [-rR] groupname
參數:
:若沒有任何參數時,表示給予 groupname 一個密碼(/etc/gshadow)
-A :將 groupname 的主控權交由後面的使用者管理(該群組的管理員)
-M :將某些帳號加入這個群組當中。
-r :to remove group pass-word. When no password is set only group
members can use newgrp(1) to join the group.
-R :disables access to the group through newgrp(1) command.
關於群組管理員(Group administrator)做的動作:
[someone@linux ~]$ gpasswd [-ad] user groupname
參數:
-a :將某位使用者加入到 groupname 這個群組當中。
-d :將某位使用者移除出 groupname 這個群組當中。
[root@localhost csie]# groupadd group1
[root@localhost csie]# gpasswd group1
Changing the password for group group1
New Password:
Re-enter new password:
[root@localhost csie]# grep group1 /etc/group /etc/gshadow
/etc/group:group1:x:500:
/etc/gshadow:group1:08IgaW1zBhnas::
[csie@localhost csie]$ newgrp group1
Password:
[csie@localhost csie]$ groups
group1 users
[csie@localhost csie]$ touch group1test
[csie@localhost csie]$ ll group1test
-rw-r--r-- 1 csie group1 0 12月 16 16:17 group1test
練習題