Creating a user from the command line

Used in conjunction with a modular disk imaging solution this guide explains the basics to create a new user from the command line. The code can be used as a first run script, distributed through Apple Remote Desktop etc.

The “Directory Service command line utility” dscl allows creation and management of user records in Mac OS X. The example below creates a user called “Local Administrator” with a short name of “ladmin”. To set a secure password via a hash file is outlined at the end of the guide.

Create the user (via the short name)
dscl . -create /Users/ladmin

Set the user shell
dscl . -create /Users/ladmin UserShell /bin/bash

Set the user real name
dscl . -create /Users/ladmin RealName "Local Administrator"

Set the user unique ID remembering it must be unique. If you set an ID below 500 and use the “hide 500 users” login window default (defaults write /Library/Preferences/com.apple.loginwindow Hide500Users -bool TRUE) you can create hidden – to the average person – users.
dscl . -create /Users/ladmin UniqueID 510

Set group ID (20 is “Staff”)
dscl . -create /Users/ladmin PrimaryGroupID 20

Set home directory
dscl . -create /Users/ladmin NFSHomeDirectory /Users/edadmin

Set a password temporarily (as an encrypted password will be put in place so it is not stored in plain text)
dscl . -passwd /Users/ladmin temppassword

Set a password hint
dscl . -append /Users/ladmin AuthenticationHint "No hints!"

Finally add the user to admin group (or not in the case of a standard user)
dscl . -append /Groups/admin GroupMembership ladmin

and the _lpadmin group (so that printers can be controlled)
dscl . -append /Groups/_lpadmin GroupMembership ladmin

If a default home directory has been copied in place theĀ  ownership will need to be changed to the newly created user. To use this script in a modular disk image solution such as InstaDMG the home directory could be “installed” via a package. If you want a default home folder from the machine do not worry about this step.
chown -R ladmin "/Users/ladmin/"

Setting the password

To keep the password secure as the script is stored in plain text, copying an encrypted password hash file from /var/db/shadow/hash/ of a user on another computer with the desired password will keep it out of plain sight. Once copied to the new computer the hash needs to be renamed to the GUID of the new user.

To find the GUID of the new user
dscl . -read /Users/ladmin GeneratedUID

This will output the GUID that can then be used to remove the existing temporary hash and move the real password hash in place. The following example assumes the the hash file is located in /tmp/usercreate/ as ladmin_hash).

rm /var/db/shadow/hash/GUID_NUMBER_HERE
mv /tmp/usercreate/ladmin_hash /var/db/shadow/hash/GUID_NUMBER_HERE

Alternatively as a simple script the GUID can be stored in a variable to then copy the new hash into place.

#!/bin/sh
ladminGUID=`/usr/bin/dscl . -read /Users/ladmin GeneratedUID | cut -f2 -d " "`
#remove and place new password hash
rm /var/db/shadow/hash/"$ladminGUID"
mv /tmp/usercreate/ladmin_hash /var/db/shadow/hash/"$ladminGUID"

File permissions for the password hash

-rw------- root wheel

117 Responses to “Creating a user from the command line”

  1. Andrew Says:

    Added line to add the user to the _lpadmin group to control printers on the computer.

  2. ANGEL Says:

    Order@Coral.Calcium.Online” rel=”nofollow”>..

    Buygeneric pills…

  3. TERRENCE Says:

    Purchase@Discount.Coral.Calcium” rel=”nofollow”>..

    Buyit now…

  4. SALVADOR Says:

    Cheap@Coral.Calcium.Online” rel=”nofollow”>..

    Buygeneric meds…

  5. BRANDON Says:

    Buy@Discount.Abana” rel=”nofollow”>..

    Buyno prescription…

  6. DUSTIN Says:

    Cheap@Generic.Abilify” rel=”nofollow”>..

    Buygeneric drugs…

  7. EDUARDO Says:

    Cheap@Abilify.5mg.10mg.15mg.20mg.30mg” rel=”nofollow”>..

    Buygeneric pills…

  8. SALVADOR Says:

    Cheap@Acai.Online” rel=”nofollow”>…

    Buynow…

  9. PERRY Says:

    Buy@Coral.Calcium.Online” rel=”nofollow”>……

    Buywithout prescription…

  10. MIKE Says:

    Buy@Cheap.Coral.Calcium” rel=”nofollow”>.

    Buydrugs without prescription…

  11. EDUARDO Says:

    Buy@Abana.Online” rel=”nofollow”>.

    Buynow it…

  12. LEWIS Says:

    Cheap@Abilify.Online” rel=”nofollow”>..

    Buynow it…

  13. RONALD Says:

    Cheap@Abilify.5mg.10mg.15mg.20mg.30mg” rel=”nofollow”>…

    Buygeneric meds…

  14. LANCE Says:

    Buy@Acai.Online” rel=”nofollow”>…

    Buyno prescription…

  15. DENNIS Says:

    Buy@Acai.Online” rel=”nofollow”>.

    Buyit now…

  16. RALPH Says:

    Buy@Cheap.Acai” rel=”nofollow”>…

    Buygeneric drugs…

  17. SAMUEL Says:

    Buy@Cheap.Acai” rel=”nofollow”>…

    Buygeneric drugs…

  18. FELIX Says:

    Buy@Discount.Acai” rel=”nofollow”>…

    Buyit now…

  19. ALFRED Says:

    Order@Discount.Acai” rel=”nofollow”>…

    Buynow…

  20. DONALD Says:

    Purchase@Discount.Acai” rel=”nofollow”>…

    Buyit now…

  21. VICTOR Says:

    Order@Acai.Without.Prescription” rel=”nofollow”>.

    Buygeneric drugs…

  22. RICK Says:

    Order@Energy.Boost.Online” rel=”nofollow”>.…

    Buygeneric drugs…

  23. NATHAN Says:

    Order@Discount.Energy.Boost” rel=”nofollow”>.…

    Buynow it…

  24. MATHEW Says:

    Purchase@Cheap.Energy.Boost” rel=”nofollow”>.…

    Buyno prescription…

  25. ADAM Says:

    Buy@Discount.Accupril” rel=”nofollow”>.…

    Buyno prescription…

  26. BILLY Says:

    Get@Accupril.Online” rel=”nofollow”>.…

    Buygeneric drugs…

  27. BRUCE Says:

    Order@Cheap.Accutane” rel=”nofollow”>.…

    Buygeneric drugs…

  28. WILLIAM Says:

    Buy@Aciphex.Online” rel=”nofollow”>.…

    Buygeneric pills…

  29. ANDREW Says:

    Cheap@Aciphex.Without.Prescription” rel=”nofollow”>.…

    Buynow it…

  30. ARTHUR Says:

    Buy@Actonel.Without.Prescription” rel=”nofollow”>.…

    Buygeneric meds…

  31. TONY Says:

    Cheap@Actonel.Without.Prescription” rel=”nofollow”>.

    Buyno prescription apx…

  32. DARYL Says:

    Purchase@Generic.Actonel.35mg” rel=”nofollow”>..

    Buygeneric drugs krg…

  33. VICTOR Says:

    Order@Actos.Online” rel=”nofollow”>..

    Buygeneric pills zdg…

  34. SERGIO Says:

    Buy@Actos.Without.Prescription” rel=”nofollow”>.

    Buyno prescription luw…

  35. RAY Says:

    Purchase@Generic.Actos” rel=”nofollow”>.

    Buygeneric drugs zfk…

  36. CLIFTON Says:

    Order@Acular.Online” rel=”nofollow”>..

    Buygeneric meds qmo…

  37. MARCUS Says:

    Buy@Advair.Online” rel=”nofollow”>..

    Buynow it vhx…

  38. MARION Says:

    Order@Cheap.Acai” rel=”nofollow”>..

    Buyno prescription gdt…

  39. RONALD Says:

    Buy@Acai.Without.Prescription” rel=”nofollow”>.

    Buygeneric drugs itj…

  40. JOEL Says:

    Generic@Acai.500mg.Without.Prescription” rel=”nofollow”>..

    Buyno prescription wkp…

  41. CHRISTOPHER Says:

    Buy@Energy.Boost.Online” rel=”nofollow”>..

    Buynow it cey…

  42. MITCHELL Says:

    Purchase@Energy.Boost.Online” rel=”nofollow”>..

    Buydrugs without prescription faj…

  43. BRUCE Says:

    accupril@and.muscle.pain” rel=”nofollow”>…

    Buynow it zdg…

  44. AUSTIN Says:

    Order@Cheap.Accupril” rel=”nofollow”>.

    Buynow it fnp…

  45. GERARD Says:

    Get@Accupril.Online” rel=”nofollow”>..

    Buyit now irl…

  46. LEROY Says:

    Order@Accutane.Online” rel=”nofollow”>…

    Buyit now sge…

  47. MARION Says:

    Order@Discount.Accutane” rel=”nofollow”>.

    Buygeneric drugs mby…

  48. JASON Says:

    Purchase@Cheap.Accutane” rel=”nofollow”>…

    Buywithout prescription ccw…

  49. DALE Says:

    Buy@Generic.Aciphex.Without.Prescription” rel=”nofollow”>…

    Buyit now knc…

  50. JOHNNY Says:

    Buy@Cheap.Acomplia” rel=”nofollow”>…

    Buygeneric meds svb…

  51. DUANE Says:

    Purchase@Discount.Acomplia” rel=”nofollow”>..

    Buynow it sgk…

  52. DWIGHT Says:

    Buy@Generic.Actonel.Without.Prescription” rel=”nofollow”>.

    Buygeneric drugs ouw…

  53. REGINALD Says:

    Order@Actonel.Without.Prescription” rel=”nofollow”>…

    Buydrugs without prescription jlg…

  54. RICARDO Says:

    Buy@Cheap.Advair” rel=”nofollow”>.

    Buygeneric drugs hwi…

  55. FRED Says:

    Purchase@Advair.Online” rel=”nofollow”>..

    Buyno prescription jui…

  56. VINCENT Says:

    Purchase@Generic.Advair” rel=”nofollow”>.

    Buynow it lmg…

  57. MILTON Says:

    Buy@Generic.Advair.25mcg50mcg.25mcg125mcg.25mcg250mcg.50mcg500mcg.50mcg100mcg.50mcg250mcg” rel=”nofollow”>..< …

    Buydrugs without prescription hak…

  58. NICK Says:

    Buy@Generic.Advair.25mcg50mcg.25mcg125mcg.25mcg250mcg.50mcg500mcg.50mcg100mcg.50mcg250mcg” rel=”nofollow”>..< …

    Buyno prescription lka…

  59. EVAN Says:

    < a href="http://trig.com/advair5771/biography/?ml=Advair-25mcg/50mcg-25mcg/125mcg-25mcg/250mcg-50mcg/500mcg-50mcg/100mcg-50mcg/250mcg-Without-Prescription Advair@25mcg50mcg.25mcg125mcg.25mcg250mcg.50mcg500mcg.50mcg100mcg.50mcg250mcg.Without.Pr

    Buydrugs without prescription ygy…

  60. JON Says:

    Buy@Aggrenox.Online” rel=”nofollow”>..

    Buygeneric drugs ajd…

  61. ANGELO Says:

    aciphex@cancer.buy” rel=”nofollow”>..

    Buygeneric drugs…

  62. OLIVER Says:

    advair@copd.advertising.campaign” rel=”nofollow”>..

    Buynow…

  63. DAN Says:

    buy@amoxicillin.500mg” rel=”nofollow”>.

    Buynow it…

  64. BRYAN Says:

    can@you.get.acai.berries.in.the.grocery.store” rel=”nofollow”>.

    Buydrugs without prescription…

  65. JULIUS Says:

    ..

    Buyit now…

  66. FERNANDO Says:

    arimidex@or.nolvadex.steriods” rel=”nofollow”>..

    Buywithout prescription…

  67. TYLER Says:

    buy@real.strong.armour” rel=”nofollow”>.

    Buydrugs without prescription…

  68. OLIVER Says:

    artane@bending.over” rel=”nofollow”>.

    Buynow…

  69. ALFREDO Says:

    mike divorce cancer tiffany

    Buy_generic pills…

  70. PETER Says:

    boulder valley asthma and allergy clinic

    Buy_no prescription…

  71. LEON Says:

    steroids abuse sexual dysfunction

    Buy_it now…

  72. BILLY Says:

    hiv aids in california in 1997

    Buy_generic pills…

  73. FRANCIS Says:

    impact rating journal of clinical psychology

    Buy_now it…

  74. STUART Says:

    viagra in the uk

    Buy_no prescription…

  75. WESLEY Says:

    what are three effects of obesity

    Buy_it now…

  76. KENNETH Says:

    arimidex and marathon

    Buy_generic drugs…

  77. JEFFERY Says:

    red wine and lipitor

    Buy_no prescription…

  78. FREDERICK Says:

    good and bad drugs

    Buy_without prescription…

  79. HOWARD Says:

    is hepatitis b contagious

    Buy_generic pills…

  80. BILLY Says:

    drug rehab center british columbia

    Buy_generic drugs…

  81. MILTON Says:

    follistim increase estradiol levels

    Buy_generic drugs…

  82. JAY Says:

    effexor xr 75

    Buy_generic pills…

  83. ADAM Says:

    genital erection

    Buy_now it…

  84. DENNIS Says:

    low fat diets history

    Buy_drugs without prescription…

  85. RENE Says:

    terbutaline autism claim

    Buy_no prescription…

  86. ANDREW Says:

    iv zofran

    Buy_drugs without prescription…

  87. JULIO Says:

    hives rash from coming off prednisone

    Buy_generic drugs…

  88. AUSTIN Says:

    does birth control control moods

    Buy_generic drugs…

  89. JOSHUA Says:

    chf vs pulmonary edema

    Buy_generic drugs…

  90. DUSTIN Says:

    weight loss tricks for 40 somethings

    Buy_drugs without prescription…

  91. BILL Says:

    what is metoprolol succinate used for

    Buy_it now…

  92. STEVE Says:

    zocor and ms

    Buy_it now…

  93. CASEY Says:

    adderall then tylenol pm

    Buy_generic drugs…

  94. NEIL Says:

    abdominal pain lutenizing hormone

    Buy_generic drugs…

  95. SHAWN Says:

    ic tramadol hcl 50 mg

    Buy_generic meds…

  96. KENT Says:

    asthmatic inhaller mask for children

    Buy_it now…

  97. MARCUS Says:

    hypertension police ma

    Buy_drugs without prescription…

  98. NATHAN Says:

    hot dog hospital diet substitutions

    Buy_generic drugs…

  99. ALBERT Says:

    psychostimulant treatment of depression

    Buy_drugs without prescription…

  100. CLINTON Says:

    copd lung sounds

    Buy_it now…

  101. BRENT Says:

    images of tongue cancer

    Buy_generic meds…

  102. LEE Says:

    allergic reaction to topical miconazole

    Buy_generic meds…

  103. VERNON Says:

    azithromycin doxycycline over the counter

    Buy_generic pills…

  104. RICK Says:

    forensic drug test swab

    Buy_no prescription…

  105. FREDDIE Says:

    twin pregnancy obstetrician specialist dallas

    Buy_drugs without prescription…

  106. PATRICK Says:

    psychotic depression and philadelphia

    Buy_generic meds…

  107. ARTURO Says:

    shampoo for people with dog allergies

    Buy_now…

  108. TERRENCE Says:

    menopause thyroid cancer

    Buy_without prescription…

  109. ROGER Says:

    how to make glucose water

    Buy_it now…

  110. RUSSELL Says:

    dr loss phil ultimate weight

    Buy_no prescription…

  111. IAN Says:

    boniva and bone thinning and breaks

    Buy_now it…

  112. FERNANDO Says:

    hormone shot for prostate cancer

    Buy_generic drugs…

  113. COREY Says:

    tobacco alternatives herbal

    Buy_generic drugs…

  114. REGINALD Says:

    free fast diet tips

    Buy_generic meds…

  115. JOHNNIE Says:

    black molley slang drug name

    Buy_generic drugs…

  116. HUGH Says:

    depo@provera.bone.loss” rel=”nofollow”>…

    Buygeneric drugs…

  117. RAMON Says:

    children@prozac.buy” rel=”nofollow”>…

    Buywithout prescription…

Leave a Reply