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 这个初始登录群组。
参考文章:
linux下查看所有用户及所有用户组
Linux /etc/passwd内容解释(超详细)
PS:你这里 /home 目录下的几个用户家目录,为什么其中那个 jiangting02 目录的所有者是 jaingting02 ? 你那时候是想输入 jiangting02,但是不小心输成了 jaingting02 吧?