解决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
相关推荐
心灵宝贝10 小时前
Kite Compositor for Mac v2.1.2 安装教程|DMG文件安装步骤(Mac用户必看)
macos
会豪13 小时前
Git命令-图解-小白专享
git
韦禾水13 小时前
IntelliJ IDEA 2023更新git凭据
git·intellij idea
他们都不看好你,偏偏你最不争气14 小时前
【iOS】UIViewController
开发语言·macos·ios·objective-c·cocoa
Yvonne爱编码14 小时前
构建高效协作的桥梁:前后端衔接实践与接口文档规范详解
前端·git·ajax·webpack·node.js
@CLoudbays_Martin1115 小时前
CDN是否能有效检测并且同时防御Ddos 和 CC 攻击?
java·服务器·网络·数据库·git·数据库开发·时序数据库
李游Leo16 小时前
Rust 开发环境安装与 crates.io 国内源配置(Windows / macOS / Linux 全流程)
windows·macos·rust
库奇噜啦呼20 小时前
【iOS】UIViewController生命周期
macos·ios·cocoa
开开心心loky1 天前
[iOS] 属性关键字
macos·ios·objective-c·cocoa·xcode
oscar9991 天前
Monorepo 全面解析:优势、挑战与适用场景
git·monorepo