88

How can I list all local user accounts in Terminal (whether logged in or not?) The commands users or who does not provide this information. OS X version is 10.6.8.

I have seen this suggested command - dscacheutil -q group

But it only lists domain user groups and non-local accounts.

IconDaemon
  • 19,234
codecowboy
  • 3,262
  • 1
    As a long time AIX user, I sure miss the system management commands they baked into their unix. lsuser would be nice to have for this purpose. – bmike Nov 01 '11 at 14:25

7 Answers7

80

How about

dscacheutil -q user | grep -A 3 -B 2 -e uid:\ 5'[0-9][0-9]'
nohillside
  • 100,768
Kevin
  • 4,142
59

Try this one. I used it to find lost hidden account.

dscl . list /Users | grep -v '^_'
user41486
  • 591
12

User accounts since 10.6 are being managed by OpenDirectory. The backend files related to users for OpenDirectory are here:

/var/db/dslocal/nodes/Default/users

Executing ls in this directory will enumerate all local users registered on the system. Executing plutil -p <file>.plist will allow you to read some properties for specified user account (i.e. current home directory path).

This is rather undocumented so I accept downvotes. However, this method can be used to inspect a system which is not running, and for which the user has only an offline disk image.

antekone
  • 220
  • I like it, but it required sudo/root to work, std admin user got a permission error. dscl works for std admin. – JL Peyret May 12 '17 at 20:49
  • Thank you, I'm struggling to reset a password for a colleague and every guide/instruction online is showing the old method which no longer works... I was even questioning if the user was corrupt or just missing... however, this has shown the user is there. I've been searching for over an hour and this has got me a little closer but nearly every site in Google is showing outdated info. – wilhil Jan 27 '21 at 13:47
  • 1
    All that's in that directory are plist files. Using ls * is not necessary, ls on its own suffices. Since the directory is not accessible by users other than root , sudo ls /var/db/dslocal/nodes/Default/users/* will fail because the file globbing is done before the sudo command, while sudo ls /var/db/dslocal/nodes/Default/users will succeed. – Elhem Enohpi Nov 02 '22 at 17:50
  • @ElhemEnohpi You're right, I've removed the * from the answer, as it indeed had no point :) – antekone Nov 03 '22 at 11:04
  • Even as root, Operation not permitted. – Devon Dec 17 '22 at 17:43
  • @Devon, works on my Ventura 13.1 with SIP enabled. – antekone Dec 19 '22 at 07:34
8

dscacheutil returns more than just local users, for example any users I've queried Directory Services for also show.

I have found this more useful:

dscl . list /Users | grep -v "^_"

Although it also returns the likes of daemon, nobody and root.

user3439894
  • 58,676
chymb
  • 491
4

JMTCW to recreate a command line friendly /etc/passwd equivalent (though not quite in the same order):

dscacheutil -q user |
    paste -d " "  - - - - - - - - |
    sed 's/^name: //;s/ [^[:space:]]*: /:/g'

Or if you prefer a space separated output (but parsing GECOS field will be a little more complicated:

dscacheutil -q user |
    cut -d: -f2 |\
    paste -d " "  - - - - - - - -
nohillside
  • 100,768
don
  • 41
2

If no user home directories were moved then ls /users will do. Except it will also list directories like 'Shared'.

iskra
  • 5,558
-3

You can also type:

who which tells you who's logged on, and where they're coming from. Useful if you're looking for someone who's actually physically in the same building as you, or in some other particular location.

w which tells you who's logged in, and what they're doing. Especially useful: the 'idle' part. This allows you to see whether they're actually sitting there typing away at their keyboards right at the moment.

techraf
  • 3,958
Jordan
  • 1