Skip to main content

How to check user and group associations on macOS

Sometimes we might have to know the list of users, groups and ids such as userid and groupid on macOS system. There are several ways to find this information. 


dsacacheutil:

The command dscacheutil -q group will output all groups with their name, ID numbers, and list of members. The command  dscacheutil -q user will output name,uid, gid, dir, shell, gecos details.

Note:  The above command will output all the groups and user details, including built-in system ones mortals were never meant to see.

Check user and group association:

We can run below command to check user and group associations to know whether a user belongs to a group or not.


dsmemberutil checkmembership -u 501 -g 1
user is not a member of the group


Or


dsmemberutil checkmembership -U user -G staff

The user user cannot be found
There was an unknown error.
User not found




Alternative methods to find group and user details on macOS

To list users in mac:

dscl . list /Users


To list groups in mac:

dscl . list /Groups


To list by group id:

dscl . list /Groups PrimaryGroupID


To list group with members:

dscl . list /Groups GroupMembership


Comments

Post a Comment