I am trying to create several user accounts with different groups in an imx6 board. Currently, no users are created in the device. Hence, I see 1000:1000 as my default user:group ID.
The scenario I need to implement is as follows:
Create two groups: grp1, grp2
Create three users: A, B, C
User A: primary group-grp1, User B: primary group-grp1, secondary group- grp2 User C: primary group-grp2
Also, these users should be able to communicate via message queues. Users (A & B) and (B & C) should be able to communicate via message queues. Users (A & C) should not be able to communicate. In a Server/Client program, I have already set mq_open file permissions as (S_IRWXU | S_IRWXG ), so that only users in the same group can be communicated.
The steps I followed to create different users are:
adduser abc
This creates a user with uid:guid 1000:1000 in /etc/passwd
abc:$1$SqakfDG7$cPlfYQT8YmkcvgzazVKvZ/:1000:1000:Linux User,,,:/home/abc:/bin/sh
addgroup grp1
addgroup grp2
Above step creates two groups in /etc/group as below.
grp1:x:1001:
grp2:x:1002:
Create user A,B with grp1, and C with grp2
adduser -G grp1 A
adduser -G grp1 B
adduser -G grp2 C
This creates user A in /etc/passwd
A:$1$E8MDq2ND$/qU4011IYRaisq7EfJh00/:1001:1001:Linux User,,,:/home/A:/bin/sh
B:$1$l2iSdPAh$ggD5NQAC1nJzbVfNVO/Kk.:1002:1001:Linux User,,,:/home/B:/bin/sh
C:$1$2Y6v67Wz$TYNxHBltTNeCDhAnnAFd3.:1003:1002:Linux User,,,:/home/C:/bin/sh
And in /etc/group
A:x:1003:
B:x:1004:
C:x:1005:
As you can see users A and B has the same group id (grp1) (i.e. 1001), and my server/client program successfully run.
The issue is to add group B into the secondary group "grp2".
Typing "id A" "id B" and "id C" gives me:
uid=1001(A) gid=1001(grp1) groups=1001(grp1)
uid=1002(B) gid=1001(grp1) groups=1001(grp1)
uid=1003(C) gid=1002(grp2) groups=1002(grp2)
Tried adding user "B" to "grp2" using usermod command as explained in Primary and secondary groups
usermod -a -G grp2 B
but "id B" doesn't change
uid=1002(B) gid=1001(grp1) groups=1001(grp1)
I even tried adding user "B" to groups grp1 and grp2 when creating it for the first time
adduser -G grp1,grp2 B
However, I get the following error.
adduser: unknown group grp1,grp2
Any idea what could I have done wrong?
Thanks alot!!