当前位置:首页 » 操作系统 » linux附加组

linux附加组

发布时间: 2023-02-26 03:32:26

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命令

热点内容
linux查看arp 发布:2025-08-13 07:53:30 浏览:474
为什么刷机还要弄以前的解锁密码 发布:2025-08-13 07:47:14 浏览:273
acfun如何上传 发布:2025-08-13 07:35:10 浏览:270
ftp共享服务器需要什么配置 发布:2025-08-13 07:33:00 浏览:543
主要数据库 发布:2025-08-13 07:15:27 浏览:178
压缩包漫画 发布:2025-08-13 07:15:25 浏览:131
服务器空岛原版如何获得矿物 发布:2025-08-13 07:08:22 浏览:437
购车时哪些是必备的配置 发布:2025-08-13 06:42:33 浏览:693
宝塔添加脚本 发布:2025-08-13 06:41:56 浏览:502
ios数据库存储 发布:2025-08-13 06:28:10 浏览:975