Reset admin password without the old password

I am trying to reset the admin password through command line. Below command used to work till High Sierra:

sudo dscl . -passwd /Users/admin new_password

But on Mojave it throws an error saying:

Permission Denied please enter old password

Please help on alternatives or how to get this working on command line (no UI solution) since the user forgot the admin password. Thanks


Solution 1:

You can reset the password in Mojave by entering recovery mode and using the "resetpassword" utility via the terminal:

  1. Boot your Mac while holding CommandR. When you get the Apple logo release the keys and allow the Mac to come up in Recovery Mode.
  2. When you get to the macOS Utilities dialog select Terminal from the Utilities menu
  3. Type resetpassword into the terminal window. In a few seconds the reset password utility will open and allow you to reset the password on your account.