我使用的命令是:
sudo useradd -g users tom
它应该将 tom 添加到组users 中,但是在检查/etc/group时我在users 中找不到 tom 。
但是,如果我只是尝试:
sudo useradd -G users jim
我发现 jim 已成功添加到用户。
有没有人遇到过这个问题?
注意:
useradd
是一个低级实用程序,强烈建议您在 Ubuntu/Debian 系统上使用adduser
(或usermod
) 代替
id -Gn username
命令来检查主要/次要成员资格,而不是依赖/etc/group
设置新用户的主要(或登录)组的-g
选项useradd
/etc/group
/etc/passwd
或使用中看到现有的 GIDid -Gn username
$ sudo useradd -g izx tom $ grep ^izx /etc/group izx:x:1000: $ grep ^tom /etc/passwd 汤姆:x:1008:1000 ::/home/tom:/bin/sh $ id -Gn 汤姆 伊兹
设置新用户的次要(或补充)组的-G
选项useradd
/etc/group
和使用id -Gn username
/etc/passwd
(与-g
上文)$ sudo useradd -G izx 哈利 $ grep ^izx /etc/group izx:x:1000:哈利 $ grep ^harry /etc/passwd 哈利:x: 1009:1009 ::/home/harry:/bin/sh $ id -Gn 哈利 哈利·伊兹