我有一个存储桶存储库,我正在尝试使用 SSH 克隆它。我按照这里的说明进行操作:https://support.atlassian.com/bitbucket-cloud/docs/set-up-an-ssh-key/
并且我可以看到我可以访问存储库:
ssh -T [email protected]
authenticated via ssh key.
You can use git to connect to Bitbucket. Shell access is disabled
但是当我尝试克隆我的存储库时,出现此错误:
git clone [email protected]:MyName/MyRepo.git
Cloning into 'MyRepo'...
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
需要注意的是,我在 Bitbucket 上有多个帐户(用于我工作的不同组织)。因此,也许 bitbucket 使用错误的 ssh 密钥来克隆存储库。我如何强制 bitbucket 使用正确的密钥或在我的 PC 上搜索正确的密钥?
我正在使用 Windows 10。
編輯1
选项-v
不显示更多信息:
git clone -v [email protected]:MyName/MyRepo.git
Cloning into 'MyRepo'...
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
编辑2
这是注释中请求的命令的输出:
ssh -T -v [email protected]
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: [email protected]
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] 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=<[email protected],[email protected],[email protected],ssh-rsa,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ecdsa-sha2-nistp256,[email protected],[email protected],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
我创建并使用的密钥有不同的名称,上面没有显示。此外,在我的 C:\Users\MyName/.ssh 文件夹中,我没有任何其他密钥或文件(只有两个文件,已知主机文件和我计划用于登录 Bitbucket 的密钥)
编辑3
git bash 中的情况有所不同。在 Git bash 中以下命令失败:
ssh -T [email protected]
[email protected]: Permission denied (publickey).
我在 PowerShell 和 git bash 中看到的内容有什么区别?
答案1
在 Windows 10 上安装 Git 后,您将获得两个单独的 OpenSSH 副本 - 一个与 Windows 捆绑在一起(Microsoft 完成的本机端口),另一个与 Git 捆绑在一起(基于 MSYS 的端口)。这两个副本大部分兼容,但并不完全兼容:例如,它们以相同的方式翻译“~/.ssh/id_rsa”,但它们使用不同的方式启动和访问 ssh-agent。
因此,如果 SSH 密钥放在非默认位置,SSH 客户端将依赖于通过 ssh-agent 而不是直接从文件中查找它 - 如果您使用 Windowsssh-add
来加载它,MSYS 将看不到它ssh.exe
,反之亦然。
为了使 Git 始终使用 Windows 版本的 ssh.exe,请设置GIT_SSH
为适当的路径:
PS> $env:GIT_SSH = "C:\Windows\System32\OpenSSH\ssh.exe"
$ export GIT_SSH="/c/Windows/System32/OpenSSH/ssh.exe"
plink.exe
(您可以以相同的方式让它使用 PuTTY ;然后它将从 PuTTY 的 Pageant 加载密钥。)
或者,将密钥文件移动到输出中列出的默认位置之一ssh -v
,例如~/.ssh/id_rsa
(即C:\Users\MyName\.ssh\id_rsa
)。