Restoring Lost Administrator on macOS Sonoma
Unfortunately it seems like all threads on this topic are closed so there is no way to post the solution in one of them. But since I have seen this issue come up again and again I wanted to provide a potential fix for everyone struggling with this.
You can lose admin privileges on a Mac in numerous ways. The last time I saw it happening was after updating a Mac Studio from Sonoma 14.5 to 14.6. The only admin account was just gone. In other cases accounts will be downgraded to standard users for all sorts of reasons. See these threads:
Restoring Lost Administrator - Apple Community
Get admin controls without admin account … - Apple Community
Starting with Sonoma recovering from such a situation got a lot harder since relaunching the macOS setup is no longer possible as seen here: What's new for enterprise in macOS Sonoma - Apple Support
Removing /private/var/db/.AppleSetupDone no longer relaunches Setup Assistant if a local user already exists on the Mac. Erase All Contents and Settings can reset the device and launch Setup Assistant.
However you can regain admin access without wiping your device! Here is how:
- Create a full backup of your system. TimeMachine or something like Carbon Copy Cloner are good options.
- Boot your Mac into Recovery Mode. Hold down CMD + R during startup on Intel platforms or long press the startup button until you see the boot options menu on Apple Silicon.
- If you are using FileVault you will need to unlock the system disk and mount it. You can do this by right clicking the disk and selecting "Mount" in Disk Utility.
- Enter the terminal via the menu bar.
- Edit the sudoers file at /etc/sudoers to include your standard user by adding the line:
yourusername ALL = (ALL) ALL
The vi text editor can be used for this:
vi /etc/sudoers
Add the line with your user name under this line (DO NOT DELETE ANYTHING):
root ALL = (ALL) ALL
Save and quit with:
:wq!
At this point we have added a standard user to the sudoers which means that we can now use that account to run commands with elevated privileges even though in macOS this user would not be considered an administrator. We can change that easily now though with a single command in the next part:
- Quit Terminal and exit recovery mode by rebooting.
- Login with your standard user account.
- Open the Terminal and enter this command (you will need to provide your password):
sudo dscl . -append /Groups/admin GroupMembership yourusername
After logging out and logging back in you will find that your user account has full administrative privileges!
If you had a different account for administrating your Mac which got deleted for some reason you might even be able to add an account with the same user name and get the user profile back.
I hope this helps some of you. Please add any additional information that I might have missed.
Mac Studio (2023)