How to create a user account in lion from single user mode

Here’s how:

Boot into single user mode (⌘S), and run the following commands:

# Mount the filesystem; start opendirectoryd:
/sbin/fsck -fy && /sbin/mount -uw /
launchctl load /System/Library/LaunchDaemons/

# Create the user account:
dscl . -create /Users/localadmin
dscl . -create /Users/localadmin UserShell /bin/bash
dscl . -create /Users/localadmin RealName "Local Admin"
dscl . -create /Users/localadmin UniqueID 502
dscl . -create /Users/localadmin PrimaryGroupID 20
dscl . -create /Users/localadmin NFSHomeDirectory /Users/localadmin

# Create the home directory:
cp -R "/System/Library/User Template/English.lproj" /Users/localadmin
chown -R localadmin:staff /Users/localadmin

# Set the password:
dscl . -passwd /Users/localadmin newPassword

# Grant admin access (optional):
dscl . -append /Groups/admin GroupMembership localadmin


You may see this error message, but don’t worry, it can be safely ignored:

launchctl: Couldn't stat("/System/Library/LaunchDaemons/"): No such file or directory
nothing found to load

To get the next unused UniqueID, run this command:

maxid=$(dscl . -list /Users UniqueID | awk '{print $2}' | sort -ug | tail -1)
echo $newid

To get the group id for the staff group, run this command:

dscacheutil -q group -a name staff

(make a note of the uid — usually 20)