解决mac下git pull、push需要输入密码
解决方法:
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