linux附加組
A. 基本組和附屬組有什麼區別 linux
Linux系統以組Group方式管理用戶,用戶和組的對應關系為多對多,即某個用戶可加入/屬於一個或多個組,某個組可以有0個、1個或多個用戶。
組的分類
從用戶的角度,分為主組和附屬組。
主組:也被稱為primary group、first group或initial login group,用戶的默認組,用戶的gid所標識的組。
附屬組:也被稱為Secondary group或supplementary group,用戶的附加組。
通過id命令可查看當前用戶的主組和附屬組
[root@localhost ~]# id root
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[root@localhost ~]# id gg
uid=503(gg) gid=503(gg) groups=503(gg)
[root@localhost ~]# id mm
uid=502(mm) gid=500(jww) groups=500(jww)
gid標識主組,groups表示用戶所屬的全部組(主組和附屬組)
1. 用戶必須有且只能有一個主組,可以有0個、1個或多個附屬組,就如我們一定會有一個用來安家的房子(類同主組),還可以有n個用於投資或其他打算的房子(附屬組)。
2. 主組也為默認組,當用戶own某個文件或目錄時,默認該文件或目錄的group owner為該用戶的主組(當然,可以通過chgrp修改group owner)。
3. 在/etc/passwd文件中,記錄行第四個欄位為gid,即用戶的主組id。
4. 在/etc/group文件中,記錄行第四個欄位為組的成員,不顯示將該組作為主組的組成員,只顯示將該組作為附屬組的組成員,因此,/etc/group的記錄行的第四個欄位沒有完整地列出該組的全部成員。
5. 當通過useradd命令創建新用戶時,可以通過-g參數指定已存在的某個組為其主組,若沒有使用-g參數,
則系統自動創建名稱和用戶名相同的組作為該用戶的主組(前提是variable in /etc/login.defs的USERGROUPS_ENAB屬性值為yes),如命令手冊的useradd關於-g參數的描述所示:
-g, --gid GROUP
The group name or number of the user′s initial login group. The
group name must exist. A group number must refer to an already
existing group.
If not specified, the bahavior of useradd will depend on the
USERGROUPS_ENAB variable in /etc/login.defs. If this variable is
set to yes (or -U/--user-group is specified on the command line), a
group will be created for the user, with the same name as her
loginname. If the variable is set to no (or -N/--no-user-group is
specified on the command line), useradd will set the primary group
of the new user to the value specified by the GROUP variable in
/etc/default/useradd, or 100 by default.
另外,可通過usermod -g 將普通用戶的主組/gid設置為系統中存在的任意某個組(永久性);
也可以通過newgrp暫時性變更當前用戶的主組/gid(只對於當前login session有效,非永久性)。
通過usermod -G 設置普通用戶的附屬組。
B. linux 怎麼修改已有用戶的所屬組
1、在linux系統中新創建的用戶是無法登錄系統的,需要為用戶配置密碼才可以進行登錄,使用passwd命令