Restore OS X Keychain

5

1

I have reset my OS X Lion Keychain by mistake. Is there any way to restore the Keychain content from Trash?

I'm asking this because I do find a Keychain Access icon in the Trash Bin. It would be a big help since the reset seems to have wiped out all the certificates.

Stanley

Posted 2012-10-15T08:07:06.330

Reputation: 185

1Well, if you have a keychain in your Trash, just right-click it and put it back. Or move it to ~/Library/Keychains. – slhck – 2012-10-15T11:51:14.803

I did a search with Finder. There doesn't seem to have any directory named Library in my OSX 10.7.5.. – Stanley – 2012-10-16T03:15:06.980

Answers

10

The Library folder where your keychains are stored is hidden by default.

First, quit Keychain Access.app.

Open Finder and press Shift Cmd G, then enter ~/Library/Keychains. Here, rename the existing default file, and drag your original file back from the Trash.

Restart Keychain Access and you should see your old one restored.

slhck

Posted 2012-10-15T08:07:06.330

Reputation: 182 472

Thanks for the answer. I have exported the keys/certificates from my home computer and imported to the office computer where the Keychain was lost. But your solution should also work since I can now find the Library folder... – Stanley – 2012-10-16T20:16:41.693

2

It's very simple to restore a keychain with macOS Mojave (and maybe earlier versions too):

  • copy the file ending with keychain-db extension, most commonly login.keychain-db, to ~/Library/Keychains with a different name to avoid overwriting the current version
  • launch Keychain Access
  • on the top menu, click File, then Add keychain, or Shift-Command-A, then point the dialog to the recovered file

You can view items and unlock the keychain with the keychain's password. The first step of copying to that location is because Keychain Access does not import the keychain, so if you delete the file, you also lose the keychain.

miguelmorin

Posted 2012-10-15T08:07:06.330

Reputation: 577

1

Here's a way to restore passwords lost back into the Keychain content.

Keychain Access will lose saved passwords often when there's a stored password in Keychain desired to be deleted; and once the item is highlighted and Edit > Delete is clicked, and, instead of just clicking the 'delete file' button, the 'delete file and all references' button gets clicked.

  1. Open Keychain Access (located in the 'Utilities' folder)
  2. Go to the "Keychain Access" menu > select "Preferences"
  3. Click the "First Aid" tab
  4. Make sure the "Synchronize login keychain password" box is checked.
  5. Close the Preferences window.
  6. Go to the "Keychain Access" menu and select "Keychain First Aid"
  7. Enter the administrator's username & password
  8. Click the "Repair" button.
  9. Click the 'Verify' button.

Now go ahead and restore all the missing, previously saved passwords back into Keychain Access:
1.) Quit the Keychain Access app.
2.) Goto ~/Library/Keychain/login.keychain file, then highlight it
3.) Enter Time Machine
4.) Goto a previous date's restore-point wherein Keychain Access held all your passwords correctly
5.) Click on 'Restore this file' —> replace the unwanted current version of this file;
6.) Goto ~/Library/Preferences/com.apple.keychainaccess.plist file, then highlight it
7.) Once again, enter Time Machine
8.) Select that very same previous restore-point-date that was used to restore the login.keychain file
9.) Click on 'Restore this file' —> replace the unwanted current version of this file.

Reopen the Keychain Access app and assure that all inadvertently deleted passwords were indeed restored,
and then
Go to the "Keychain Access" menu and select "Keychain First Aid"
Enter the account's username & password
Click the "Repair" button.

Close the Keychain Access app.

Ed Pendowski

Posted 2012-10-15T08:07:06.330

Reputation: 51

Alas this recipe doesn't work on Yosemite. Secure Notes didn't get restored. – Sherwood Botsford – 2017-01-21T21:22:27.753

In macOS Mojave, the First Aid option is mising from Keychain Access. – miguelmorin – 2019-05-22T12:42:50.390