解决mac下git pull、push需要输入密码

解决方法:

1.强制配置 SSH 自动加载钥匙串

编辑 SSH 配置文件

复制代码
vi ~/.ssh/config

Host *
  AddKeysToAgent yes          # 自动将密钥添加到 ssh-agent
  UseKeychain yes             # 明确使用钥匙串存储密码
  IdentityFile ~/.ssh/id_rsa  # 替换为你的私钥路径
2.修复 Shell 环境配置

编辑 shell 配置文件

复制代码
vi ~/.bash_profile

添加以下代码(解决 ssh-agent 不自动加载的问题)

复制代码
# 自动启动 ssh-agent 并加载密钥
if [ -z "$SSH_AUTH_SOCK" ]; then
   eval "$(ssh-agent -s)" > /dev/null
   ssh-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
相关推荐
2501_915909063 小时前
iOS 应用上架全流程解析,苹果应用发布步骤、ipa 上传工具、TestFlight 测试与 App Store 审核经验
android·macos·ios·小程序·uni-app·cocoa·iphone
Jouzzy3 小时前
【iOS安全】iPhone X iOS 16.7.11 (20H360) Palera1n MacOS版 越狱教程
macos·ios·iphone
@@神农18 小时前
maven的概述以及在mac安装配置
java·macos·maven
不老刘20 小时前
macOS/Linux ClaudeCode 安装指南及 Claude Sonnet 4.5 介绍
linux·macos·ai编程·claude·vibecoding
2401_884810741 天前
git知识点
git
醉、倾城1 天前
面向开发人员的macOS入门教程
macos·策略模式
小牛itbull1 天前
从 Vercel 构建失败谈 Git 大小写敏感性问题:一个容易被忽视的跨平台陷阱
git
chainbees1 天前
Git账号配置 SSH 密钥
运维·git·ssh
Brian Xia1 天前
Lazygi - 让git操作不再困难
git
2501_916013742 天前
iOS 26 系统流畅度检测 从视觉特效到帧率稳定的实战策略
android·macos·ios·小程序·uni-app·cocoa·iphone