Is it possible to re-create a lost account with given homedir and UID in macOS?

0

1

Because of a full disk crash of my PowerMac (using macOS 10.9.5 (Mavericks)), I lost an account named entry: No trace of it can be found when using “System Preferences > Users and Groups,” or with terminal commands such as su my_lost_account. However, all the files are still there, with the unamed uid, in the still correctly named home directory.

Is it possible for me to create a new account with the exact same login name and UID of my lost account and assign it with the home directory that already has content that I want to keep?

Thanks in advance for any clues.

ELw38fr

Posted 2018-05-26T21:04:04.807

Reputation: 13

I'm having a hard time working out what your question is. Can you edit it to be more clear? – Blackwood – 2018-05-26T23:41:58.653

Is the OS X user account model pure Unix with /etc/passwd and such or is there a secondary internal mechanism at play? If just Unix-y then simply re-creatign the appropriate line in /etc/passwd and then setting a password may do... and the line may be in a older backup copy of the file at /etc/passwd- – ivanivan – 2018-05-28T04:14:28.723

Answers

0

I believe you can create a specific account without overwriting your data. But I'd strongly suggest making a copy of your data before trying.

To create a new user with a specific name and UID, use dscl from the command line:-

dscl . -create /Users/<user>
dscl . -create /Users/<user> UserShell /bin/bash 
dscl . -create /Users/<user> RealName "<real name>"
dscl . -create /Users/<user> UniqueID "<UID>"
dscl . -create /Users/<user> PrimaryGroupID "<GID>"
dscl . -create /Users/<user> NFSHomeDirectory /Users/<user>
dscl . -create /Users/<user> Password 

The final command above will ask you for a password.

e.g. for user "fred", real name "Fred Quimby", UID 501, GID 20, with home directory /Users/fred

dscl . -create /Users/fred
dscl . -create /Users/fred UserShell /bin/bash 
dscl . -create /Users/fred RealName "Fred Quimby"
dscl . -create /Users/fred UniqueID "501"
dscl . -create /Users/fred PrimaryGroupID "20"
dscl . -create /Users/fred NFSHomeDirectory /Users/fred
dscl . -create /Users/fred Password

arcdale

Posted 2018-05-26T21:04:04.807

Reputation: 429