简体   繁体   English

添加公钥Bitbucket后,git clone存储库访问被拒绝

[英]git clone repository access denied after adding public key Bitbucket

I am trying to access my repositories on my bitbucket account via ssh, but no matter what I try, I can't seem to get access. 我正在尝试通过ssh访问我的bitbucket帐户上的存储库,但是无论我如何尝试,我似乎都无法访问。 I own all the repositories on my account as well, so it's not a matter of not having read/write privileges. 我也拥有我帐户上的所有存储库,因此没有读取/写入特权也无济于事。

I created a new public/private key combo and added the public key to my account (I have done this with other computers as well). 我创建了一个新的公用/专用密钥组合并将公用密钥添加到我的帐户中(我也使用其他计算机完成了此操作)。 And I did the following commands in my command line: 我在命令行中执行了以下命令:

eval 'ssh-agent' //I've also tried eval 'ssh-agent -s'
ssh-add /path/to/private/key

Still denied access. 仍被拒绝访问。 I have setup SSH access before on Bitbucket without any issues using this same process, but for some reason, I can't get this to work. 我之前已经在Bitbucket上使用相同的过程设置了SSH访问权限,没有任何问题,但是由于某些原因,我无法使它正常工作。

Update: 更新:

I ran ssh -v bitbucket.org and here was the output: 我运行ssh -v bitbucket.org,结果如下:

OpenSSH_7.2p2 Ubuntu-4ubuntu2.7, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /home/eric/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to bitbucket.org [18.205.93.0] port 22.
debug1: Connection established.
debug1: identity file /home/eric/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/eric/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/eric/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/eric/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/eric/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/eric/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/eric/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/eric/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.7
debug1: Remote protocol version 2.0, remote software version conker_1.1.53-1da6f80 app-155
debug1: no match: conker_1.1.53-1da6f80 app-155
debug1: Authenticating to bitbucket.org:22 as 'eric'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
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:zzXQOXSRBEiUtuE8AikJYKwbHaxvSc0ojez9YXaGp1A
debug1: Host 'bitbucket.org' is known and matches the RSA host key.
debug1: Found key in /home/eric/.ssh/known_hosts:1
Warning: Permanently added the RSA host key for IP address '18.205.93.0' to the list of known hosts.
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/eric/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: eric@thanos
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: eric@thanos
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/eric/.ssh/id_dsa
debug1: Trying private key: /home/eric/.ssh/id_ecdsa
debug1: Trying private key: /home/eric/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

It looks like it's trying to find a private key named id_rsa, which, for the computer I am working on now, is already in use on another bitbucket account, so it can't be used for this account. 似乎正在尝试查找名为id_rsa的私钥,对于我现在正在使用的计算机,该私钥已在另一个bitbucket帐户中使用,因此无法用于该帐户。 Is there some way to override that naming convention so that I can add a custom key not named id_rsa? 有什么方法可以覆盖该命名约定,以便我可以添加一个名为id_rsa的自定义键?

First, try that with a private key without passphrase: you will avoid having to deal with the ssh-agent, which, for testing, is easier. 首先,尝试使用不带密码短语的私钥:您将避免处理ssh-agent,这对于测试来说更容易。

Second, make sure to generate a private key to the old PEM format, not the new OpenSSH one : 其次,确保生成旧PEM格式的私钥,而不是新的OpenSSH私钥:

ssh-keygen -m PEM -t rsa -P "" -f afile

And see if the issue persists. 并查看问题是否仍然存在。

Your stack trace also includes: 您的堆栈跟踪还包括:

 Authenticating to bitbucket.org:22 as 'eric' 

Make sure your SSH URL is git@bitbucket.org , not eric@bitbucket.org : the key is there to authenticate you within the session, but the session is always opened with the git account. 确保您的SSH URL是git@bitbucket.org而不是 eric@bitbucket.org :密钥在会话中用于对您进行身份验证,但是会话始终使用git帐户打开。

I figured out what was causing the issue. 我弄清楚是什么原因引起的。 By default, bitbucket looks for a private key named "id_rsa" when using the default git url ( git@bitbucket.org:<username>/<repository>.git ). 默认情况下,使用默认的git url( git@bitbucket.org:<username>/<repository>.git )时,bitbucket会查找名为“ id_rsa”的私钥。 Since mine was already tied to another account, it kept throwing up errors. 由于我的帐户已经绑定到另一个帐户,因此它不断抛出错误。 It is, however, possible to add additional keys to the account using the information here: 但是,可以使用以下信息向帐户添加其他密钥:

https://confluence.atlassian.com/bitbucket/set-up-additional-ssh-keys-271943168.html . https://confluence.atlassian.com/bitbucket/set-up-additional-ssh-keys-271943168.html

Worked for me and now I have SSH access to my account. 为我工作,现在我可以通过SSH访问我的帐户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM