How to export Users and Groups with dsexport

You can use the Terminal command ”dsexport” to save a file of your macOS users or groups that you can later import again, if needed.

This article has been archived and is no longer updated by Apple.

Exporting user or group records

Use the following Terminal commands to create a file on your desktop containing a list of users or groups. You can compress and save these files as a backup archive.

Passwords are not included in the exported file, so you need to manually set them after the import is complete. 

Export local users:

dsexport ~/Desktop/LocalUserExport.out /Local/Default dsRecTypeStandard:Users

Export local network users:

dsexport ~/Desktop/LNUserExport.out /LDAPv3/127.0.0.1 dsRecTypeStandard:Users

Export local groups:

dsexport ~/Desktop/LocalGroupsExport.out /Local/Default dsRecTypeStandard:Groups

Export local network groups:

dsexport ~/Desktop/LNGroupsExport.out /LDAPv3/127.0.0.1 dsRecTypeStandard:Groups

Importing user or group records

Use the following Terminal commands to import files you exported earlier. Place the file you want to import on the desktop of the user you are currently logged in as, then use the terminal command that matches the file type you are importing.

Import local users:

dsimport  ~/Desktop/LocalUserExport.out /Local/Default I --username <local administrator Short Name>   --recordtype dsRecTypeStandard:Users

Import local network users:

dsimport  ~/Desktop/LNUserExport.out /LDAPv3/127.0.0.1 I --username <Directory administrator short name> --recordtype dsRecTypeStandard:Users

Import local groups:

dsimport  ~/Desktop/LocalGroupsExport.out /Local/Default I --username <local administrator short name> --recordtype dsRecTypeStandard:Groups

Import local network groups:

dsimport  ~/Desktop/LNGroupsExport.out /LDAPv3/127.0.0.1 I --username <directory administrator short name> --recordtype dsRecTypeStandard:Groups

Learn more

You can learn more about dsexport and dsimport from their man pages.

Published Date: