My friend was over yesterday and decided that he would upgrade his macbook to osx leopard (10.5). I'm not sure how it happened but it seems that something got on the dvd and caused a read error and a failed upgrade. After cleaning off the disk, the upgrade completed successfully. The only problem was that his user seemed to be gone. All of his attempts with his various passwords failed. He looked fairly dejected at being locked out of his now leopardized laptop.

The first thing we did to troubleshoot was boot the macbook into target disk mode (hold down T when powering it on). Looking around the filesystem revealed that his user folder still existed in /Users, with the username we expected.

Our next attempt was single user mode (hold down apple-S when powering on). Single user mode drops you into a root shell with readonly access to the filesystem. So we did the following:

fsck -yf 
mount -uw /
launchctl load /System/Library/LaunchDaemons/com.apple.DirectoryServices.plist 
launchctl load /System/Library/LaunchDaemons/com.apple.DirectoryServicesLocal.plist 
passwd #this will change root's password, you will be prompted to enter it twice
dscl
That last command will load the directory services command line app (they removed netinfo manager in leopard, otherwise you could easily reboot and fix the problem using a gui from the root account). At the dscl prompt we entered the following:
list Local/Default/Users
create Local/Default/Users/<your_old_username>
create Local/Default/Users/<your_old_username> UniqueID 501
create Local/Default/Users/<your_old_username> PrimaryGroupID 501
create Local/Default/Users/<your_old_username> NFSHomeDirectory /Users/<your_old_username>
create Local/Default/Users/<your_old_username> UserShell /bin/bash
create Local/Default/Users/<your_old_username> RealName 
After that was complete we rebooted the machine by typing shutdown -r now. When the machine booted up again, my friend was able to log into his account. All of his settings had been preserved since they all live in your home directory. The only exceptions were his user account picture, full name and password.

I hope someone else finds this useful, it took a good bit a of playing around to figure this out.

6 Responses to “fix a missing user account in leopard”

  1. segfault segfault Says:
    just testing, looks like I broke commenting when upgrading mephisto a few weeks back
  2. chromatic chromatic Says:
    Try this one on for size - my friend's user account seems to be un-admin'd... the account which used to have admin privs is now "standard". the existing account is otherwise fine. Any ideas for that? :)
  3. segfault segfault Says:
    You should be able to enable the root acount and then use that account to fox your friend's. Alternatively you can just use the command line tool to add the admin group to the user. Good luck.
  4. kaliban kaliban Says:
    Awesome! Thanks so much! I had nearly the same problem, and this solution worked almost exactly as described! In case it's not obvious to someone - after the final command in the second batch & prior to typing the shutdown command, you'll need to first type 'exit' to get out of the dscl. Also, things were slightly different for me since I had multiple user accounts. The main important factor in this case seems to be using the correct user id/group id for each account. In other words, I used the ID 501 for what turned out to be the second account in the order originally created, so I needed to use ID 502 instead, which I didn't figure out until after the fact. Having erroneously assigned 501 to the acct that should have been 502, my old password didn't seem to work - but after several tries I was prompted for the old master password in order to change my user password, which all worked fine. Having logged in, I didn't have permission to access my previous folders, so I ended up rebooting back into single user mode and following the directions a second time from the above article. This time, however, I substituted the 'change' command for the 'create' command, and reassigned the correct number to my account and group id. syntax for the 'change' command is exactly the same as for 'create', except you enter the old value followed by the new value such as... change Local/Default/Users/<your_old_username> UniqueID 501 502 change Local/Default/Users/<your_old_username> PrimaryGroupID 501 502 I hope the above is useful to someone...
  5. jake jake Says:
    Thank you sooooo much. I've been looking everywhere for an answer to this problem. thanks so much for posting the solution. :)
  6. Beaker Beaker Says:
    This sounds like the fix I am looking for. I just restored my HD from a Time Machine backup, and in the process my user names/accounts got mixed up. My account (the one I'm trying to restore) will show up under /Users/, but will not show up when logging in. So I'm hopeful your fix will work. That said, I'm not able to execute the last command of the second batch as you show it. When I execute the last create, I'm assuming you're telling me to put in the "real name" of the account I'm trying to restore. All goes according to plan...but when I reboot, the account will show up, but the account will not recognize my password. So, I log into my "maintenance" account (with administrator rights), and try to change the password. Unfortunately, my original account will not show up under User Accounts in System Prefs. So, I swung my cursor up to the fast switch area of the desktop, and my account is listed--but again, won't recognize my password. Suggestions? It looks to me like I'm halfway there...but the second half looks as significant as the first. Any help would be greatly appreciated, since I'm pretty much a dunce when it comes to Unix.
  7. Conan Conan Says:
    Thanks, this was just the ticket! Btw, you missed puttinh <real> on the last one. It should read: create Local/Default/Users/<your_old_username> RealName <real>

Leave a Reply