You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何取消Git远程仓库的GPG验证?SSH连接故障修复

解决步骤

一、切换到SSH远程仓库地址

你当前使用HTTPS地址克隆仓库,这是触发旧GPG密钥解密提示的核心原因之一,先将远程地址替换为SSH格式:

  1. 针对已克隆的仓库,执行:
git remote set-url origin git@alya.gitlab.myserver.com:myrepo/myrepo.git
  1. 新克隆直接使用SSH地址:
git clone git@alya.gitlab.myserver.com:myrepo/myrepo.git test

二、验证SSH密钥配置有效性

  1. 修正本地SSH私钥权限(必须为600,否则SSH会拒绝加载):
chmod 600 ~/.ssh/id_rsa  # 若使用ed25519密钥则替换为id_ed25519
  1. 启动并加载SSH Agent:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
  1. 测试与GitLab服务器的SSH连通性:
ssh -T git@alya.gitlab.myserver.com

返回Welcome to GitLab, @yourusername!则说明SSH配置正常。

三、清理旧GPG凭证残留

若之前用GPG加密了Git凭证缓存,旧密钥失效后会持续触发解密失败提示:

  1. 查看当前Git凭证助手配置:
git config --global credential.helper
  1. 若返回包含gpg的配置(如store --gpg),可选择:
  • 移除GPG加密的凭证助手:
git config --global --unset credential.helper
  • 或更新为新GPG密钥加密(若仍需使用HTTPS):
git config --global credential.helper "store --gpg --gpg-program gpg2"

重新输入HTTPS凭证后,会自动用新GPG密钥加密存储。

四、修复gpg-agent连接失败问题

  1. 检查gpg-agent是否运行:
pgrep gpg-agent

无进程则手动启动:

gpg-agent --daemon --enable-ssh-support
  1. 在~/.bashrc或~/.zshrc中添加环境变量配置:
export GPG_TTY=$(tty)
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
gpgconf --launch gpg-agent

重新加载shell配置:

source ~/.bashrc  # 使用zsh则替换为source ~/.zshrc
  1. 再次尝试重新加载agent:
gpg-connect-agent reloadagent /bye

五、确认Git全局GPG密钥配置

检查全局配置的签名密钥是否为新生成的密钥ID:

git config --global --list | grep signingkey

若不符则重新设置:

git config --global user.signingkey <你的新GPG密钥ID>

内容的提问来源于stack exchange,提问作者doks

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 06:45:58