解決方法:
1.強制配置 SSH 自動加載鑰匙串
編輯 SSH 配置文件
vi ~/.ssh/config
Host *AddKeysToAgent yes # 自動將密鑰添加到 ssh-agentUseKeychain yes # 明確使用鑰匙串存儲密碼IdentityFile ~/.ssh/id_rsa # 替換為你的私鑰路徑
2.修復 Shell 環境配置
編輯 shell 配置文件
vi ~/.bash_profile
添加以下代碼(解決 ssh-agent 不自動加載的問題)
# 自動啟動 ssh-agent 并加載密鑰
if [ -z "$SSH_AUTH_SOCK" ]; theneval "$(ssh-agent -s)" > /dev/nullssh-add --apple-use-keychain ~/.ssh/id_rsa 2>/dev/null
fi
使配置生效
source ~/.bash_profile
3.徹底清理并重新添加密鑰
清除所有已緩存的密鑰
ssh-add -D
重新添加密鑰到鑰匙串
ssh-add --apple-use-keychain ~/.ssh/id_rsa