I tried:
sudo useradd -s "/bin/false" -g [existingGroupName] [userNameToAdd]
After the command I looked it up in /etc/group
, but the user is not in the [existingGroupName]
. Why is that so?
I tried:
sudo useradd -s "/bin/false" -g [existingGroupName] [userNameToAdd]
After the command I looked it up in /etc/group
, but the user is not in the [existingGroupName]
. Why is that so?
That's because
/etc/group
shows the secondary group members (users), not primary ones.-g
inuseradd
sets the primary group the user would belong to, which must be only one; whereas-G
adds user to single or multiple secondary groups.You can check user's primary group (and secondary groups) along with IDs with the
id
command:As a side note, unless intentional, you should use the
adduser
Perl wrapper ofuseradd
instead of using it directly.Another note would be to use
getent group
instead of directly reading/parsing/etc/group
for getting a group info e.g.: