How to Fix macOS Keychain Locked / Not Unlocking
In this tutorial, you'll learn about How to Fix macOS Keychain Locked / Not Unlocking. We cover key concepts, practical examples, and best practices.
The Problem
Your Mac repeatedly prompts for the keychain password:
An application wants to access the keychain "login".
Enter the keychain password to allow this.
Or apps fail to access saved passwords:
The operation couldn't be completed. (OSStatus error -25293.)
The login keychain is locked or the keychain password no longer matches the user account password.
Quick Fix
Step 1: Unlock the keychain via command line
security unlock-keychain ~/Library/Keychains/login.keychain-db
Enter your login password when prompted. This unlocks the keychain for the current session.
Step 2: Update the keychain password to match the login password
security set-keychain-password ~/Library/Keychains/login.keychain-db
You are prompted for the old keychain password (if known) and the new password. The new password should match your macOS login password.
Step 3: Run Keychain First Aid
- Open Keychain Access (from Utilities)
- Click Keychain Access > Keychain First Aid
- Enter your administrator credentials
- Click Start
Keychain First Aid verifies and repairs keychain files.
Step 4: Reset the login keychain
If you forgot the keychain password:
- Open Keychain Access
- Right-click login in the left sidebar
- Select Delete Keychain "login"
- Log out and log back in
macOS creates a new empty login keychain. You will need to re-enter saved passwords.
Step 5: Reset the default keychain
security default-keychain -d user
security list-keychains -d user -s login.keychain
security default-keychain -s ~/Library/Keychains/login.keychain-db
Step 6: Fix iCloud Keychain sync
- System Preferences > Apple ID > iCloud
- Toggle Passwords & Keychain off and back on
- Enter your iCloud password
Step 7: Delete corrupted keychain files
cd ~/Library/Keychains/
ls -la
If you find multiple login.keychain-db files with strange names, move them aside:
mv login.keychain-db login.keychain-db.backup
Log out and back in to generate a fresh keychain.
Step 8: Check for keychain locking settings
In Keychain Access > Edit > Change Settings for Keychain "login":
- Lock after X minutes of inactivity: Set to a longer interval or "Never"
- Lock when sleeping: Uncheck if convenient
Prevention
- Keep the login keychain password in sync with your macOS login password.
- Unlock the keychain once per session rather than repeatedly.
- Back up keychains regularly via Keychain Access > File > Export.
Common Mistakes with keychain locked
- Using
returnto exit a function early instead of wrapping a pure value in the monad - Mixing let bindings with <- bindings in do notation, producing type errors
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
These mistakes appear frequently in real-world MACOS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
DodaTech Tool Reference
Durga Antivirus Pro's Password Manager integrates with the macOS Keychain to audit saved credentials and flag weak or reused passwords across your applications.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro