ssh-keychain-unlock
Original:🇺🇸 English
Translated
Use when Claude Code auth fails over SSH on macOS, keychain is locked in headless/remote sessions, or setting up Claude Code on a Mac for remote access
9installs
Sourcesoulmachine/skills
Added on
NPX Install
npx skill4agent add soulmachine/skills ssh-keychain-unlockTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →SSH Keychain Unlock for Claude Code on macOS
Overview
Claude Code stores credentials in the macOS Keychain ( service). When accessing a Mac via SSH (no GUI session), the login keychain is locked, causing Claude Code to appear unauthenticated.
Claude Code-credentialsWhen to Use
- Claude Code says it's not logged in when accessed via SSH
- shows the keychain is locked
security show-keychain-info ~/Library/Keychains/login.keychain-db - Setting up a Mac Mini or headless Mac for remote Claude Code usage
Solutions
Option 1: Interactive Unlock on SSH Login
Add to :
~/.zshrcbash
# Unlock macOS keychain for SSH sessions (needed for Claude Code auth)
if [[ -n "$SSH_CONNECTION" ]]; then
security unlock-keychain ~/Library/Keychains/login.keychain-db 2>/dev/null
fiPrompts for macOS login password each SSH session. Simple but requires manual input.
Option 2: Auto-Unlock at Boot (Headless)
For fully headless operation with no password prompt:
1. Create password file (, permissions ):
~/.claude/.keychain-password600bash
echo 'YOUR_MACOS_PASSWORD' > ~/.claude/.keychain-password
chmod 600 ~/.claude/.keychain-password2. Create unlock script (, permissions ):
~/.claude/unlock-keychain.sh700bash
cat > ~/.claude/unlock-keychain.sh << 'SCRIPT'
#!/bin/bash
security unlock-keychain -p "$(cat ~/.claude/.keychain-password)" ~/Library/Keychains/login.keychain-db
SCRIPT
chmod 700 ~/.claude/unlock-keychain.sh3. Create LaunchAgent ():
~/Library/LaunchAgents/com.claude.unlock-keychain.plistbash
cat > ~/Library/LaunchAgents/com.claude.unlock-keychain.plist << 'PLIST'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.claude.unlock-keychain</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>__HOME__/.claude/unlock-keychain.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
PLIST
# Fix path
sed -i '' "s|__HOME__|$HOME|g" ~/Library/LaunchAgents/com.claude.unlock-keychain.plist4. Load the agent:
bash
launchctl load ~/Library/LaunchAgents/com.claude.unlock-keychain.plistQuick Reference
| Command | Purpose |
|---|---|
| Check keychain lock status |
| Manually unlock (interactive) |
| Test auto-unlock script |
| Load LaunchAgent |
| Unload LaunchAgent |
Common Mistakes
- Wrong permissions on password file - Must be (owner-only). Others can read your macOS password otherwise.
600 - Forgetting to load the LaunchAgent - Creating the plist isn't enough; run to activate it.
launchctl load - Password file out of sync - If you change your macOS password, update too.
~/.claude/.keychain-password