-G 使用后,并未移除原来的群组
来源:3-11 群组的管理

我会做饭
2019-11-19
老师你好,为什么我的用了-G,但原来的群组并没有被移除呢
5回答
-
Oscar
2019-11-22
usermod 的命令手册见 https://linux.die.net/man/8/usermod
或者你用
man usermod
来查看命令手册,可以看到
-g, --gid GROUP The group name or number of the user's new initial login group. The group must exist. Any file from the user's home directory owned by the previous primary group of the user will be owned by this new group. The group ownership of files outside of the user's home directory must be fixed manually. -G, --groups GROUP1[,GROUP2,...[,GROUPN]]] A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option. If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current supplementary group list.
说明得比较清楚了。
-g 参数是用于设定用户的 initial login group(初始登录群组),并不会受之后用 -G 参数添加或修改的附加群组的影响。
-G 参数是用于设定用户除了 initial login group(初始登录群组)之外的其他附加群组(A list of supplementary groups which the user is also a member of. If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current supplementary group list.)。
-aG 用于添加新的附加群组,不会删掉目前的附加群组。a 是 append(附加)的缩写。
我实际测试了。比如我这里的 thomas 用户:
跟你的情况类似,thomas 的群组里面还是有 friends 这个群组。因为这个 friends 群组是最初通过 -g 参数来设定的,是 thomas 这个用户的 initial login group(初始登录群组),并不会受之后用 -G 参数添加或修改的附加群组的影响。
我查看了 /etc/group 这个包含群组的信息的文件,发现:
我又查看了 /etc/passwd 文件,里面有用户及用户ID,组ID的信息,等等:
可以看到用户 thomas 的用户 ID 是 1001,而他的 组 ID 是 1002(1002 就是 friends 这个群组的 组 ID)。 thomas 用户的组 ID 是 1002,所以他目前一直属于 friends 这个初始登录群组。
参考文章:
PS:你这里 /home 目录下的几个用户家目录,为什么其中那个 jiangting02 目录的所有者是 jaingting02 ? 你那时候是想输入 jiangting02,但是不小心输成了 jaingting02 吧?
112020-02-29 -
慕的地8023689
2022-01-10
-G只会修改你之前通过-G添加的附加组,通过-g添加的群组是不受-G影响的
00 -
w慕莱坞
2020-04-02
-g修改完在/etc/group中是查看不到组对应的用户,而-G修改完在文件中可以看到对应的组和用户
00 -
cn_five
2020-03-09
-G<群组> 修改用户所属的附加群组。-g 对用户的初始登录´新组的名称或编号。本组必须存在。大G是添加附属组,小g是设定或者更改原始组。
00 -
我会做饭
提问者
2019-11-22
好的,谢谢老师你的详细解答,我这边晚上回去再试试,再次感谢???
00
相似问题