views:

1966

answers:

5

I need to add a new user via the command line in single-user mode. I reinstalled OS X earlier, and for some reason, it didn't create my user account properly. Now I can't log in. So I'm wondering how exactly I can go about creating a new user account without reinstalling everything.

I tried this, but it didn't work: http://osxdaily.com/2007/10/29/how-to-add-a-user-from-the-os-x-command-line-works-with-leopard/

Thanks in advance.

+1  A: 

http://www.macosxhints.com/article.php?story=20030603190314390

Evansbee
Leopard (non-server) has no nireport or niutil, unfortunately...syntax looks very similar to dscl though...
Collin Klopfenstein
That's because the "ni" in those utilities is for "NetInfo", which has (thankfully) been replaced as of Leopard. Collin is on the right track, dscl is the replacement, but using it is not trivial, either. Although I'm sure OS X is designed primarily for GUI addition/manipulation of users, for situations like yours, it would be nice if the process from Terminal were a easier and better documented.
Quinn Taylor
+1  A: 

Perhaps try:

sudo useradd -n newuser

This works under BSD, no idea if it works under MacOS X but worth a shot.

Edit: Wow... How fail is MaxOSX at account creation!

sudo useradd -n newuser

vs

sudo niutil -create / /users/newuser 
sudo niutil -createprop / /users/newuser uid 502
sudo niutil -createprop / /users/newuser gid 502
sudo niutil -createprop / /users/newuser realname "Longer Name"
sudo niutil -createprop / /users/newuser home "/Users/newuser "
sudo niutil -createprop / /users/newuser shell "/bin/tcsh"
sudo niutil -createprop / /users/sharedDir shell "Public"
sudo niutil -createprop / /users/newuser passwd "*"
sudo passwd newuser 
sudo ditto /System/Library/User\ Template/English.lproj /Users/newuser 
sudo chown -R newuser :group /Users/newuser
Bayard Randel
Heh...that was the first thing I tried. That nor adduser exist in OS X.
Collin Klopfenstein
Like I said, niutil is a OS X Server command, and not available on stock OS X installs :-/
Collin Klopfenstein
bugger, pity they couldn't retain some of those more generic bsd system tools :(
Bayard Randel
+4  A: 
rm /var/db/.AppleSetupDone

...and then reboot normally. With that file gone, OS X launches its first-run Setup Assistant and (among other things) lets you create a new account.

BTW, the reason niutil isn't there has nothing to do with whether it's a server or not -- it's because Apple got rid of NetInfo (its old database for storing local users) in 10.5, and replaced it with a new XML-based system. If you want to do niutil-ish things in 10.5, you can either use dscl (this is actually a bit complicated in single-user mode because directory services aren't running) or create/edit the XML files by hand.

Gordon Davisson
You may need to boot into single-user mode (hold down Cmd-S at startup) and mount the filesystem in read/write mode (there will be instructions on screen on how to do so) before you can delete the file, especially if you don't have an admin account at all.
Clinton Blackmore
A: 

Dear Gordon, I wish to find out the admin password (I am the admin, but I forgot). I do not wish to delete the other accounts. Will the rm /var/db/ .AppleSetupDone wipe away the other users?

A: 

Seems like if it didn't create your user account correctly you probably need to reinstall again in case other things didn't get set up correctly.

Hardwareguy