You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Windows 10下多Bitbucket账户场景SSH克隆仓库失败及PowerShell与Git Bash差异问题求助

Windows 10下多Bitbucket账户场景SSH克隆仓库失败及PowerShell与Git Bash差异问题求助

我在Windows 10上有多个Bitbucket账户(对应不同的工作组织),最近尝试用SSH克隆其中一个仓库时遇到了问题,想请大家帮忙排查下。

我已经按照Bitbucket的SSH密钥配置指南完成了设置,并且执行ssh -T git@bitbucket.org时能成功认证,输出如下:

authenticated via ssh key.
You can use git to connect to Bitbucket. Shell access is disabled

但当我执行克隆命令时:

git clone git@bitbucket.org:MyName/MyRepo.git

却收到权限拒绝的错误:

Cloning into 'MyRepo'...
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

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

我怀疑是多账户的问题导致Bitbucket使用了错误的SSH密钥来克隆仓库,想请教怎么强制它使用我指定的密钥,或者让它在我的设备上找到正确的那个?


我已经尝试的排查步骤:

  • -v参数重新执行克隆命令,没有得到更多有效信息:

    git clone -v git@bitbucket.org:MyName/MyRepo.git
    

    输出依然是:

    Cloning into 'MyRepo'...
    git@bitbucket.org: Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    
  • 执行ssh -T -v git@bitbucket.org查看详细认证日志,发现日志里尝试的密钥中,没有我专门为这个Bitbucket账户创建的自定义名称密钥。而且我的C:\Users\MyName/.ssh文件夹里只有两个文件:known_hosts和我准备使用的目标密钥,没有其他密钥文件。完整日志如下:

    OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
    debug1: Connecting to bitbucket.org [2406:da00:ff00::22c5:2ef4] port 22.
    debug1: Connection established.
    debug1: identity file C:\\Users\\MyName/.ssh/id_rsa type -1
    debug1: identity file C:\\Users\\MyName/.ssh/id_rsa-cert type -1
    debug1: identity file C:\\Users\\MyName/.ssh/id_dsa type -1
    debug1: identity file C:\\Users\\MyName/.ssh/id_dsa-cert type -1
    debug1: identity file C:\\Users\\MyName/.ssh/id_ecdsa type -1
    debug1: identity file C:\\Users\\MyName/.ssh/id_ecdsa-cert type -1
    debug1: identity file C:\\Users\\MyName/.ssh/id_ed25519 type -1
    debug1: identity file C:\\Users\\MyName/.ssh/id_ed25519-cert type -1
    debug1: identity file C:\\Users\\MyName/.ssh/id_xmss type -1
    debug1: identity file C:\\Users\\MyName/.ssh/id_xmss-cert type -1
    debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1
    debug1: Remote protocol version 2.0, remote software version conker_eda5298d7e 60ddf9423977
    debug1: no match: conker_eda5298d7e 60ddf9423977
    debug1: Authenticating to bitbucket.org:22 as 'git'
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: algorithm: curve25519-sha256@libssh.org
    debug1: kex: host key algorithm: rsa-sha2-512
    debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
    debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
    debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
    debug1: Server host key: ssh-rsa SHA256:zzXQOXSRBEiUtuE8AikJYKwbHaxvSc0ojez9YXaXXXXX
    debug1: Host 'bitbucket.org' is known and matches the RSA host key.
    debug1: Found key in C:\\Users\\MyName/.ssh/known_hosts:7
    debug1: rekey out after 134217728 blocks
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: SSH2_MSG_NEWKEYS received
    debug1: rekey in after 134217728 blocks
    debug1: Will attempt key: MyName@DESKTOP-KQ34PDP RSA SHA256:ypYnv30FvYLDVY1c2p7PngPPjy4uPR8pn4yXXXXXX agent
    debug1: Will attempt key: C:\\Users\\MyName/.ssh/id_rsa
    debug1: Will attempt key: C:\\Users\\MyName/.ssh/id_dsa
    debug1: Will attempt key: C:\\Users\\MyName/.ssh/id_ecdsa
    debug1: Will attempt key: C:\\Users\\MyName/.ssh/id_ed25519
    debug1: Will attempt key: C:\\Users\\MyName/.ssh/id_xmss
    debug1: SSH2_MSG_EXT_INFO received
    debug1: kex_input_ext_info: server-sig-algs=<ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ssh-rsa,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ecdsa-sha2-nistp256,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-512,ssh-dss>
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug1: Authentications that can continue: publickey
    debug1: Next authentication method: publickey
    debug1: Offering public key: MyName@DESKTOP-KQ34PDP RSA SHA256:ypYnv30FvYLDVY1c2p7PngPPjy4uPR8pn4yXXXXXXX agent
    debug1: Server accepts key: MyName@DESKTOP-KQ34PDP RSA SHA256:ypYnv30FvYLDVY1c2p7PngPPjy4uPR8pn4yXXXXXX agent
    debug1: Authentication succeeded (publickey).
    Authenticated to bitbucket.org ([2406:da00:ff00::22c5:2ef4]:22).
    debug1: channel 0: new [client-session]
    debug1: Entering interactive session.
    debug1: pledge: network
    debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
    authenticated via ssh key.
    You can use git to connect to Bitbucket. Shell access is disabled
    debug1: channel 0: free: client-session, nchannels 1
    Transferred: sent 3016, received 2276 bytes, in 0.2 seconds
    12841.5
    debug1: Exit status 0
    received
    

额外的疑惑:

我还发现一个奇怪的现象:在PowerShell里执行ssh -T git@bitbucket.org能成功认证,但在Git Bash里执行同样的命令却报错:

git@bitbucket.org: Permission denied (publickey).

想请教这两个环境之间有什么差异导致了这个情况?

备注:内容来源于stack exchange,提问作者mans

火山引擎 最新活动