[CentOS] username list?

Stephen Harris lists at spuddy.org
Fri Jul 13 03:11:04 UTC 2007


On Thu, Jul 12, 2007 at 06:28:04PM -0700, Carlos Daniel Ruvalcaba Valenzuela wrote:

Please don't top-post.  That's not standard for this list.  I've fixed
your message...

> On 7/12/07, Rogelio Bastardo <scubacuda at gmail.com> wrote:
> >Where/how in CentOS can I get a nice list of all the usernames on the
> >system?

This isn't really a CentOS specific question; this is generic Unix.

> The file /etc/passwd should show all the system users (if you are
> using local loging and not NIS or other remote authentication
> systems), you will also see many systems users (like a user for
> apache, mysql, etc).

That will only work for local users.  The answer you really want is
"getent passwd".

This handles everything nsswitch.conf does (NIS, LDAP, xyzzy, whatever).

To get just a list of usernames:
  getent passwd | cut -d: -f1 | sort -u

What it _doesn't_ do is handle specialised authentication; just because
a person may have an account on a box doesn't mean a person can login or
otherwise access the box.  Naming services do _not_ match authentication
and authorisation services.

However, if your environment is that complicated then you shouldn't be
asking such simple questions on this list :-)  For a simple environment,
or even a moderately complicated one (NIS, NIS+, LDAP with no specialised
PAM rules) then "getent passwd" will do the job.

-- 

rgds
Stephen



More information about the CentOS mailing list