The Group File: /etc/group

For various administrative purposes, in particular, controlling access to files and other system resources, it is useful to organize users into groups.

The set of groups to which a user belongs is defined by the combination of the group ID field in the user’s password entry and the groups under which the user is listed in the group file. This strange split of information across two files is historical in origin. In early UNIX implementations, a user could be a member of only one group at a time. A user’s initial group membership at login was determined by the group ID field of the password file and could be changed thereafter using the newgrp(1) command, which required the user to supply the group password (if the group was password protected). 4.2BSD introduced the concept of multiple simultaneous group memberships, which was later standardized in POSIX.1-1990. Under this scheme, the group file listed the extra group memberships of each user. (The groups(1) command displays the groups of which the shell process is a member, or, if one or more usernames are supplied as command-line arguments, then the group memberships of those users.)

The group file, /etc/group, contains one line for each group in the system. Each line consists of four colon-separated fields, as in the following examples:

users:x:100:
jambit:x:106:claus,felli,frank,harti,markus,martin,mtk,paul

In order, these fields are as follows:

To record that the user avr is a member of the groups users, staff, and teach, we would see the following record in the password file:

avr:x:1001:100:Anthony Robins:/home/avr:/bin/bash

And the following records would appear in the group file:

users:x:100:
staff:x:101:mtk,avr,martinl
teach:x:104:avr,rlb,alc

The fourth field of the password record, containing the group ID 100, specifies membership of the group users. The remaining group memberships are indicated by listing avr once in each of the relevant records in the group file.