List User Accounts on Mac from Command Line

Jul 5, 2016 - 5 Comments

Terminal in OS X

Mac administrators may find themselves in a situation where they need to display a list of all user accounts on a particular Mac by way of the command line. We’ll review a few methods for advanced individuals to list all accounts, both user and system, on any Mac with any version of Mac OS X system software.

A few preliminary basic approaches to this would be to access the login screen or to list the contents of the /Users directory, though if a user account is hidden then it would not display at the login screen and it’s equally simple to obfuscate a user from the /Users folder. Additionally, the existence of a name in the /Users/ directory is not foolproof, because you can delete a user account but preserve that users home directory. As a result, while those approaches may be appropriate for the casual Mac user looking to show what users they have on a computer, neither of those methods are particularly sufficient for most admin needs. But, by turning to the command line you can reveal all user accounts on a Mac, whether they are general user accounts of active users, admin accounts, as well as any system account.

How to List All User Accounts on a Mac from Command Line

Open the Terminal if you haven’t done so already, either on the local machine you want to list user accounts for, or by connecting to a remote Mac you’d like to see the user accounts on. We’ll then use the ‘dscl’ command, which works in all versions of Mac OS X system software.

View All Users & Accounts on a Mac

dscl . list /Users

The benefit (or trouble) with this approach is that it lists not only all user accounts on a Mac but it also shows every daemon and server process account. This would include usernames like Paul, Bob, Jill, but also daemons, system accounts, and process users like networkd, windowserver, daemon, nobody, root, _spotlight, _ard, _appserver, _iconservices, and many more.

If the complete list of users is thus undesirable, you can easily exclude all the _underscore daemon and process accounts by running the output through grep, as we’ll show next.

Show User Accounts Only

dscl . list /Users | grep -v '_'

This command will filter out any of the _ underscore prefixed daemon users, which are not actually user accounts. You’ll get a much shorter list of user names returned as a result, but you’ll still find three user names included that are not typical user accounts, but are normal to be found on Mac OS X installs; daemon, nobody, and root.

Show All User Accounts, User Directories, & User GECOS Info on a Mac

Another approach would be to show and list a detailed account list of user accounts, the associated user account directory, and the user account GECOS info (which is usually a description of the account or a full user name). If you find yourself wondering what on earth some of the system accounts and process user ID accounts in the aforementioned lists are, this approach offers more details, including the gecos description for each account (for example, _qtss user is the QuickTime Streaming Server daemon)

dscacheutil -q user

The output of that command will be rather extensive, so you may want to pipe the result through more or less or redirect it into a text file for easier parsing.

There are likely other means of displaying all user accounts on a Mac, regardless of system version, if you know of an effective of informative method not covered here, do share it in the comments.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: Paul Horowitz in Command Line, Mac OS X, Tips & Tricks

5 Comments

» Comments RSS Feed

  1. cthulhu says:

    I use a different trick for this to list admin account / admin users

    dscl . -read /Groups/admin GroupMembership

    WIll list all administrator accounts on the Mac

  2. Alistaire Smialek says:

    If you have Fast User Account Switching enabled in Mac OS (X) you can see the list of possible user names on the Mac by clicking on the name or icon in the upper right corner.

  3. sean says:

    Just checking something as I am not a command line user.
    When I use dscl . list /Users | grep -v ‘_’
    I get an account called “nobody”. Who is this and should I get rid of it?

    • Mark says:

      Absolutely NOT.

      NOBODY owns no files, is NOT in a privileged group, and has ONLY the permissions that any user would have (less the user directory, and control of those files) IOW, it’s a process account. It’s common on UN*X type systems.

      LEAVE NODOBY ALONE.

  4. Ashraf Fahmy says:

    I have listed the users on my mac suspecting that someone had hacked my Mac as it had turned out to be very slow.
    I got many users with “_” before them, I got root, nobody daemon.
    That is in addition to my created users. Does this mean that everything is ok, or should I start worrying!

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates