2

I came across the command getent group sudo to list sudoers in sudo group and I got the output sudo:x:27:lion now I wounder what is the meaning of :x:, colon and 27 ... also I see same symbols in /etc/passwd... so what do these symbols mean ?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
WLION
  • 295
  • 1
  • 6

2 Answers2

5

getent group displays entries from the group database. The local group database is the file /etc/group, whose format is documented in the group(5) man page.

Each line in this file is a database entry, representing one group. The columns on a line are separated by a colon. The second column is the password hash.

The user database /etc/passwd has a similar format, with different contents in the columns. The first two columns are the name and password hash, like with the group.

These files have a column for the password only for backward compatibility. Normally the password hash is not in the publicly readable user/group database, but in another database called the shadow database (/etc/shadow for users, /etc/gshadow for groups) which contains password hashes and other account information such as expiry dates, and which can only be read by privileged processes.

It's extremely rare to put a password on a group: normally some users are in the group and the other users aren't. So you can expect the gshadow entries to have * in the password hash column (this isn't a valid hash, it's a marker indicating that there is no way to gain access to the user/group by entering a password).

4

It's the same output as this:

grep ^sudo: /etc/group
  • sudo is the group name
  • x represents a password field
  • 27 is the GID (Group ID)
  • lion is a member of the sudo group

Groups can have passwords, too; and their passwords are stored in /etc/gshadow.

  • man gpasswd
  • man gshadow
Petr Skocik
  • 28,816
Christopher
  • 15,911
  • It's not always the same as grep ... /etc/group because getent group can fetch group info from multiple sources (including /etc/group, LDAP, NIS, and other sources defined in /etc/nsswitch.conf). This is why it's recommended to use getent rather than directly extracting info from files like /etc/passwd, /etc/group etc. – cas May 19 '16 at 00:57