为何git push无法通过1Password完成GitHub身份验证?
GitHub Push失败(Permission denied (publickey))排查与解决
问题描述
在GitHub创建仓库并克隆到本地后,添加文件、提交到本地仓库均正常,提交时1Password验证也无问题,但执行git push命令时出现身份验证失败报错:
git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights
已执行操作:
- 使用1Password生成ed25519密钥,添加到GitHub作为签名和身份验证密钥
- 本地完成1Password与GitHub的配置,通过
ssh-add -L确认allowed_signers - 执行
git commit --allow-empty -message="Testing SSH Signing"验证本地SSH密钥有效 - 克隆仓库时1Password验证成功,但push操作始终失败
补充信息:
- 尝试HTTPS和SSH两种仓库地址均报错
- 执行
git push -u origin master、git push -u origin均失败 - 执行
ssh -vvv github.com:username/reponame.git时出现地址解析错误:
OpenSSH_9.0p1, LibreSSL 3.3.6 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files debug1: /etc/ssh/ssh_config line 54: Applying options for * debug2: resolve_addr: could not resolve name github.com:username/reponame.git as address: nodename nor servname provided, or not known debug1: resolve_canonicalize: hostname github.com:username/reponame.git is an unrecognised address debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/Users/me/.ssh/known_hosts' debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/Users/me/.ssh/known_hosts2' debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling debug1: Connecting to github.com:username/reponame.git port 22.
核心排查与修复步骤
1. 修正SSH测试命令格式
你执行的ssh -vvv github.com:username/reponame.git格式错误,正确的GitHub SSH连接验证命令应为:
ssh -T git@github.com
若命令返回Hi <你的用户名>! You've successfully authenticated, but GitHub does not provide shell access.,说明SSH身份验证本身正常;若仍报错,继续以下排查。
2. 检查远程仓库地址配置
执行命令查看当前远程地址是否正确:
git remote -v
- SSH地址需为
git@github.com:username/reponame.git,无拼写或符号错误 - HTTPS地址需为
https://github.com/username/reponame.git
若地址错误,用以下命令修改:
# 修改为SSH地址 git remote set-url origin git@github.com:username/reponame.git # 或修改为HTTPS地址 git remote set-url origin https://github.com/username/reponame.git
3. 确认1Password SSH代理状态
- 打开1Password,进入设置 > 开发者,确保「使用1Password作为SSH代理」已开启
- 检查你的ed25519密钥在1Password中标记为「允许SSH访问」
- 执行
ssh-add -D清空本地密钥缓存,重启终端后重新触发1Password代理加载密钥
4. 验证GitHub密钥权限
登录GitHub:
- 进入个人设置 > SSH和GPG密钥,确认添加的ed25519密钥同时开启了「身份验证」和「签名」权限
- 若使用仓库级部署密钥,进入对应仓库设置 > 部署密钥,确保密钥开启「写入」权限
5. 排查HTTPS模式身份验证
若HTTPS地址也报错,检查git凭据助手配置:
git config --global credential.helper
若返回值不是op,执行以下命令配置1Password为HTTPS凭据助手:
git config --global credential.helper op
重新执行push,触发1Password的HTTPS验证流程。
6. 检查本地SSH配置文件
查看~/.ssh/config文件,确保GitHub相关配置正确,建议保留以下基础配置:
Host github.com IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock" User git Port 22
注释掉其他可能干扰1Password代理的冗余配置。
内容的提问来源于stack exchange,提问作者JaviQQ
相关产品推荐
相关产品推荐

