Skip to main content

(macOS) Create a new user worklet

  • September 20, 2019
  • 3 replies
  • 233 views

cfrieberg
Forum|alt.badge.img

I'm exploring a custom worklet to create a new user.

So far this has been successful creating the user.
However when trying to login, the password does not work.

Please help if you think of a way around this.

#!/bin/bash
sudo ddcl . -create /Users/automox
sudo dscl . -create /Users/automox UserShell /bin/bash
sudo dscl . -create /Users/automox RealName Automox
sudo dscl . -create /Users/automox UniqueID 9999
sudo dscl . -create /Users/automox NFSHomeDirectory /Local/Users/automox
sudo dscl . -passwd /Users/automox password123
sudo dscl . -append /Groups/admin GroupMembership automox

ps - Don’t use password123… I’m sure that goes without saying 🙂 Also there’s better ways to make users, but we’re trying to conjure this up for a specific use case.

This topic has been closed for replies.

3 replies

Forum|alt.badge.img
  • Automox Employee
  • September 20, 2019

great work here cfrieberg, dscl is indeed the preferred method for creating user accounts on macOS. One limitation of that tools is that it does not create a user’s home folder. Based on the last line it seems like you want this account to have admin rights, so I fixed that below as well.

#!/bin/bash

user_short_name="automox"
user_long_name="Automox"
user_password="Password123"
user_unique_id="9999"

dscl . -create /Users/"$user_short_name"
dscl . -create /Users/"$user_short_name" UserShell /bin/bash
dscl . -create /Users/"$user_short_name" RealName "$user_long_name"
dscl . -create /Users/"$user_short_name" UniqueID "$user_unique_id"
dscl . -create /Users/"$user_short_name" NFSHomeDirectory /Users/"$user_short_name"
dscl . -passwd /Users/"$user_short_name" "$user_password"
dscl . -create /Users/"$user_short_name" PrimaryGroupID 20 #for an admin user, use 80 for a standard user
cp -R /System/Library/User\ Template/English.lproj /Users/"$user_short_name"
chown -R "$user_short_name":admin /Users/"$user_short_name"

cfrieberg
Forum|alt.badge.img
  • Author
  • Novice
  • September 20, 2019

This is great! Thank you Tim.

I tested it out in a custom worklet, it successfully created a user account that I could log into.

I wonder if there’s a way to automate the account setup steps (siri, language, etc that come up after loggin in)

Thanks again!


PaulB
  • Former Automox Employee
  • September 26, 2019

There are ways to force a password reset on next login, if that seems like a nice feature to add.