• Main Menu
  • How to List Unix Users


    List Logged In Unix Users

    Unix has many commands to list users who are logged in.

    These commands include ‘w,’ ‘who,’ and ‘users:’


    $ w
    9:51PM up 99 days, 5:39, 2 users, load averages: 0.83, 0.90, 0.90
    USER TTY FROM LOGIN@ IDLE WHAT
    will p0 c-66-164-235-73. 8:11AM - w
    spencer p3 c-66-164-235-73. 8:26PM 1:24 pine

    $ who
    will ttyp0 Jul 26 08:11 (66.164.235.73)
    spencer ttyp3 Jul 26 20:26 (66.164.235.73)

    $ users
    spencer will

    List All Unix Users

    To list all users on a Unix system, even the ones who are not logged in, look at the /etc/password file.


    $ cat /etc/passwd
    ...
    george:*:1009:1009:George Washington:/home/george:/usr/bin/bash
    tom:*:1016:1016:Thomas Jefferson:/home/tom:/usr/bin/bash
    al:*:1017:1017:Alexander Hamilton:/home/alex:/usr/bin/bash
    ...

    Use the ‘cut’ command to only see one field from the password file.

    For example, to just see the Unix user names, use the command “$ cat /etc/passwd | cut -d: -f1.”


    $ cat /etc/passwd | cut -d: -f1
    ...
    george
    tom
    al
    ...

    Or to only see the GECOS field (i.e. the account holder’s real name), try this:


    $ cat /etc/passwd | cut -d: -f5
    ...
    George Washinton
    Thomas Jefferson
    Alexander Hamilton
    ...

    Note that users will also see Unix system accounts such as “root,” “bin,” and “daemon” in the /etc/passwd file. These system accounts are not Unix users.

    List All Unix Users Under NIS(yp)

    NIS (Network Information System) in the current name for what was once known as yp (Yellow Pages). The purpose of NIS is to allow many machines on a network to share configuration information, including password data. NIS is not designed to promote system security. If your system uses NIS you will have a very short /etc/passwd file that includes a line that looks like this:

    +::0:0:::i

    To view the real password file use this command `ypcat passwd`

    NIS and NIS+ are being replaced by LDAP (Lightweight Directory Access Protocol).

    Got Something To Say:

    Your email address will not be published. Required fields are marked *

    3 comments
    1. Mario

      14 June, 2013 at 2:28 pm

      To all you software developers out there, do not believe that all the users are in the /etc/passwd file. The example given here is more accurately described as “to list all the users with account information stored locally on a Unix system” use cat /etc/passwd.

      Many shops do not use /etc/passwd for anything but the system accounts. Some shops use NIS (yes, still) and many others use LDAP. There are other sources as well, and they all have their own commands.

      If you want to check whether a user exists or not, use the “id” utility. It’ll work no matter what your sources of information are. There is no way to list all the users regardless of information source that I am aware of.

      Reply
      • WillSpencer

        15 June, 2013 at 10:00 am

        You’re right. This article made a lot more sense under our old site design where it was logically followed by the article on NIS(yp). Both articles are quite brief, so I’ve merged them into one article.

        Reply
    2. Robert Williams

      15 May, 2011 at 6:00 pm

      ls /home also works if the users you are interested in have a home directory

      Reply
    Unix
    177 queries in 0.500 seconds.