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

Windows环境下通过SSH连接Bitbucket Server失败问题求助

问题场景

执行ssh -p [port] -v git@[host]时,SSH认证成功,输出包含debug1: Authentication succeeded (publickey);但执行git clone --recurse-submodules ssh://git@[host]:[port]/[repo].git却报错:

git@[host]: Permission denied (publickey).
fatal: Could not read from remote repository.

已将公钥添加至Bitbucket Server,多次更换密钥仍无法解决。

解决方案
  • 确认Git使用的SSH密钥
    Git可能未使用你添加到Bitbucket的密钥,执行带调试信息的Git命令查看密钥加载路径:

    GIT_SSH_COMMAND="ssh -v" git clone --recurse-submodules ssh://git@[host]:[port]/[repo].git
    

    在输出中查找debug1: Trying private key: xxx的行,确认路径是否为目标密钥文件。若不符,可通过两种方式修正:

    • 将目标密钥移动到SSH默认路径(如~/.ssh/id_rsa)
    • 在~/.ssh/config中添加主机配置,指定对应密钥:
      Host [host]
          HostName [host]
          Port [port]
          User git
          IdentityFile ~/.ssh/你的密钥文件名
      
      配置后可使用简化命令克隆:git clone git@[host]:[repo].git
  • 修正密钥文件权限
    SSH对密钥权限要求严格,权限过宽会被拒绝,执行以下命令设置正确权限:

    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/你的密钥文件
    chmod 644 ~/.ssh/你的密钥文件.pub
    
  • 检查Bitbucket仓库权限

    • 确认添加公钥的Bitbucket账号对目标仓库拥有读取权限(克隆操作需读权限)
    • 核对Bitbucket中添加的公钥内容,确保和本地~/.ssh/你的密钥文件.pub完全一致,无多余空格、换行或缺失字符
  • 排查SSH代理问题
    若使用ssh-agent管理密钥,确保目标密钥已被代理加载:

    ssh-add ~/.ssh/你的密钥文件
    

    执行ssh-add -l查看已加载密钥列表,确认目标密钥存在其中

内容的提问来源于stack exchange,提问作者Michał Leszczyński

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 13:10:58