How to Read ‘id’ and ‘/etc/group’ in User Management

groupsuser-managementusers

This is a follow-up question to Why is a user not a member of their private group (UPG)? although the first question isn't really necessary to understand this one.


The command id seems pretty clear…

test@test ~ $ id test
uid=1000(test) gid=1000(test) groups=1000(test),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),129(sambashare)

it shows the UID and GID of test (resp. its UPG) and then additionally lists all groups of which the user test is a member.


But then how should /etc/group be read?

test@test ~ $ less /etc/group | grep test
adm:x:4:syslog,test
cdrom:x:24:test
sudo:x:27:test
dip:x:30:test
plugdev:x:46:test
lpadmin:x:113:test
test:x:1000:
sambashare:x:129:test

The group-name at the beginning is pretty clear and also that the number is the GID; and after that the names of the group-members are listed. But why isn't the second last line test:x:1000:test instead of test:x:1000: to indicate, that the user test is member of the group test?

bonus question: what is the x in the second column for?

Best Answer

The answer is in your question

[id] shows the UID and GID of test (resp. its UPG) and then additionally lists all groups of which the user test is a member.

The line you are asking about:

test:x:1000:

test, the user, is a member of test, the group. This is defined in /etc/passwd. The groups in /etc/passwd defines the 'primary' group of user test. Additional or supplementary groups are defined in /etc/group: in this case test user is also member of adm, cdrom, sudo, etc.

Also see

As for "why?", I am afraid this may be a UNIX standard. I.e., it was created this way nearly 50 years ago and that's the way it has been done.

Related Question