Spiral Arm Logo

Jono's technical notes

Tuesday, March 13, 2007

Creating a user from the commandline on OS X

The following will create a user USER_NAME in the group USER_NAME
with a home directory /Users/USER_NAME, it assumes you have sudo
access and are currently in /Users

  1. Find the next free uid by running the following

      nireport . /users name uid

  2. create user, assuming a free uid of 505 from the previous step.

      This should be a single line.

      echo USER_NAME::505:505:USER_NAME build user:0:0:USER_NAME
      User:/Users/USER_NAME:/bin/bash | sudo niload -v passwd /

  3. Set password

      sudo passwd USER_NAME

  4. create group

      echo 'USER_NAME:*:505: USER_NAME' | sudo niload -v group /

  5. create user directory

      mkdir USER_NAME

  6. change ownership

      sudo chown USER_NAME:USER_NAME USER_NAME

  7. make sure you can login

      ssh USER_NAME@localhost

As an aside here is how to delete a user via the command line.

  1. check the user exists

      dscl . read /users/USER_NAME

  2. delete the users group

      sudo dscl . delete /groups/USER_NAME

  3. delete the user

      sudo dscl . delete /users/USER_NAME

  4. delete user home directory

      sudo rm -rf USER_NAME

Taken from

Labels: