In Terminal, I used, useradd liao2, as I would also do in Linux, but it failed:

useradd liao2
-bash useradd: command not found

I also tried using sudo:

sudo useradd liao2
sudo: useradd: command not found

How can a user be added from Terminal?


Update: A better explanation of what I answered can be found here. Please use that information instead.

ORIGINAL: macOS doesn't have the same unix commands as Linux. To add a user, properly use the system preferences pane for Users & Groups.

System Preferences will have a Users & Groups section. There you can click the + icon in the bottom left to add a user as standard or administrator.

macOS uses a directory service to administrate users. The adduser command equivalent for Mac is:

dscl . -create /User/USERNAME_HERE

You may need admin privledges, therefore sudo will be needed like so

sudo dscl . -create /User/USERNAME_HERE

Followed by a long chain of commands to set up that user properly. Please see the manual page for more detailed information.

  • surely it doesn't mean that there is a command for adding user? – aircraft Jun 14 '17 at 3:48
  • 3
    This is an excellent resource: blog.travismclarke.com/post/osx-cli-user-management – Aaron Williams Aug 29 '18 at 7:47
  • 1
    It says invalid path – IceFire Mar 6 '20 at 8:29
  • 1
    @IceFire answer has outdated info. In newer macOS versions, you have to do this instead: sudo dscl localhost -create /Local/Default/Users/USERNAME_HERE – Simon Kissane Jun 14 '20 at 9:29
  • 1
    @Павел users command only shows currently logged-in users. If you create a user with dscl localhost -create, it won't show up in users until you log in as that user. That doesn't mean the user isn't created. A better test is calling id on the user you created. Which actually does work, provided you set the required attributes on the node (UniqueID, PrimaryGroupID, NFSHomeDirectory, UserShell) – Simon Kissane Apr 17 at 17:23

A similar tool to useradd is /usr/sbin/sysadminctl on macOS . There isn't a manual but /usr/sbin/sysadminctl -h is explanatory. You should be aware that the command and options will be stored in your shell's history. Note the last line of the help output so that the user password is not stored in your shell's history.


Not the answer you're looking for? Browse other questions tagged .