iMac Reset Password or Factory Reset without losing the data
Posted: 25 Mar 2016, 5:57am - Friday

Restart your computer and press COMMAND + S then this will enter to terminal mode. First you need to mount the "root" path before you can modify the disk.

:/ root# mount -uw /
Now after mounting the root path, you have two option here, factory reset or reset password of a user so you can access the files. Factory Reset In factory reset, all you need is to delete the file /var/db/.applesetupdone then OS X will detect that the system has run the first time (but the data are all intact).
rm /var/db/.applesetupdone
User Reset Password In user reset password, this is what you will do:
  1. go to /Users directory then list the files and folders
  2. whoever you want to reset the password, just type passwd <username>
  3. then this will ask you for the new password and confirm new password
  4. that's it
:/ root# cd /Users
:/ root# ls -lsa
:/ root# password user1
Enter New Password: 
Confirm Password:

:/ root# reboot
then type exit or reboot or restart the machine. then you all good to go...