基本组和附属组有什么区别 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 设置普通用户的附属组。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-12-01
基本组,相当于你的家,
附属组,相当于你在外面租的房子,只要你有钱想租多少都行
就是说你的用户(test)可以有很多个附属组!
不知道这样说你能明白吗?
第2个回答  2010-12-01
同一个用户可以在多个组里,比如oracle用户 属于DBA组 又属于oracle组。二个组的权限他都有本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网