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

GitLab镜像至Bitbucket Cloud:认证失败问题求助

GitLab镜像同步Bitbucket认证错误解决

问题描述

尝试将本地GitLab实例的提交同步至Bitbucket仓库,已创建Bitbucket Access Token,但SSH和HTTPS协议均出现认证错误:

SSH协议错误:

13:get remote references: create git ls-remote: exit status 128, stderr: "Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
"

HTTPS协议错误:

13:get remote references: create git ls-remote: exit status 128, stderr: "remote: Invalid credentials
fatal: Authentication failed for 'https://bitbucket.org/USERNAME/xxxx-repo-name-xxxx.git/'
"

已确认凭据正确且将bitbucket.org加入known-hosts,仍无法解决。


HTTPS协议认证失败解决步骤

  • 检查Access Token权限:确保Bitbucket生成的Access Token勾选了Repository Write权限,仅Read权限无法完成镜像推送。
  • 修正URL格式:GitLab镜像配置的HTTPS URL必须包含用户名和Token,格式为:
    https://<BITBUCKET_USERNAME>:<ACCESS_TOKEN>@bitbucket.org/<USERNAME>/xxxx-repo-name-xxxx.git
    
    替换<BITBUCKET_USERNAME>为你的Bitbucket用户名,<ACCESS_TOKEN>为生成的令牌,不要遗漏@符号。
  • 本地验证Token有效性:在终端执行以下命令,确认Token能正常访问仓库:
    git ls-remote https://<USERNAME>:<TOKEN>@bitbucket.org/<USERNAME>/xxxx-repo-name-xxxx.git
    
    若返回仓库引用列表,说明Token有效;否则重新生成Token。

SSH协议认证失败解决步骤

  • 确保GitLab运行用户的known_hosts配置正确:GitLab通常以git用户运行,需在该用户的~/.ssh/known_hosts中添加bitbucket.org密钥:
    1. 登录GitLab服务器,切换到git用户:
      sudo su - git
      
    2. 添加bitbucket.org主机密钥:
      ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts
      
    3. 验证连接:执行ssh git@bitbucket.org,若提示"You've successfully authenticated..."则说明主机密钥配置正确。
  • 配置SSH密钥配对:
    1. 在git用户下生成SSH密钥(若未生成):
      ssh-keygen -t ed25519 -C "gitlab-mirror@your-domain.com"
      
    2. 复制公钥内容(~/.ssh/id_ed25519.pub),添加到Bitbucket仓库的Access keys中(仓库设置→Access keys→Add key),并设置权限为Write。
    3. 验证SSH连接:
      git ls-remote git@bitbucket.org:<USERNAME>/xxxx-repo-name-xxxx.git
      
      能返回仓库引用则说明密钥配置正确。

通用排查要点

  • 确认Bitbucket仓库存在,且你的账号拥有该仓库的Write权限。
  • 检查GitLab镜像配置的推送模式为Push,而非Pull。
  • 查看GitLab日志获取详细错误:
    • Rails日志:/var/log/gitlab/gitlab-rails/production.log
    • GitLab Shell日志:/var/log/gitlab/gitlab-shell/gitlab-shell.log

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 08:10:19