How to Fix Remote Desktop Authorization Failed Problem on Mac OS X

We recently replaced a failing hard drive on an iMac. After the drive was replaced, we had problems connecting to it through Remote Desktop. We always got an error message about authorization failure. I am pretty sure the username and password were entered correctly. The problem persisted even though I restarted the Remote Management several times.

I found an article on how to fix this problem. The article was published in 2008. Some preferences have changed, but, based off the instructions, I was able to fix the problem on a 10.6 machine. The idea is to stop Remote Management/Desktop on the machine and delete the preferences. All the steps are performed on Terminal or a SSH session.

  1. Disable Remote Management/Desktop.
    sudo /System/Library/CoreServices/RemoteManagement/ -deactivate -configure -access -off
  2. Delete the preferences.
    sudo rm -rf /var/db/RemoteManagement/
    sudo rm /Library/Preferences/
    sudo rm -r /Library/Application\ Support/Apple/Remote\ Desktop/
  3. Restart Remote Management/Desktop
    sudo /System/Library/CoreServices/RemoteManagement/ -activate -configure -access -on -users username -privs -all -restart -agent -menu