0

For example, typing compgen -u on an Ubuntu box returns a list of users. This includes more users than are listed in /etc/passwd . So the question is when using bash completion to list out users, where does the list come from?

Taryn East
  • 27,486
  • 9
  • 86
  • 108

2 Answers2

2

/etc/passwd is the default source of user account information on UNIX-like systems, but it's often supplemented by other sources, paricularly on machines that are part of some larger organization that needs to keep that information consistent.

NIS (formerly known as "YP") is one common system. LDAP is another. I'm sure there are others.

The getent passwd command should show you all the relevant account information. On my machine (which doesn't use NIS or LDAP), it's equivalent to cat /etc/passwd; on yours, it will probably show additional information.

The various getpw*() functions (getpwuid(), getpwnam(), getpwent()) retrieve user account information, equivalent to what's in /etc/passwd plus whatever supplement your system uses. Presumably both the getent command and bash use this mechanism to obtain the relevant information.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
1

You can run strace -o compgen.out bash -c 'compgen -u' and then look at the compgen.out file to try to find out what it is using.

On my machine that file ends with an open("/etc/passwd", O_RDONLY) followed by the writing of the output.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • This is the method I ended up using and was able to identify configuration files used and the unix socket that was queried to retrieve the user list. – user3866591 Jul 24 '14 at 17:13