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

时间:2019-03-29 23:43:23

标签: git ssh

我正在尝试通过ssh访问我的bitbucket帐户上的存储库,但是无论我如何尝试,我似乎都无法访问。我也拥有自己帐户中的所有存储库,因此没有读/写权限也没关系。

我创建了一个新的公用/专用密钥组合,并将公用密钥添加到我的帐户中(我也使用其他计算机完成了此操作)。我在命令行中执行了以下命令:

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

仍然拒绝访问。我之前在Bitbucket上已经使用相同的过程设置了SSH访问权限,没有任何问题,但是由于某些原因,我无法使其正常工作。

更新:

我运行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).

似乎正在尝试查找名为id_rsa的私钥,对于我现在正在使用的计算机,该私钥已在另一个bitbucket帐户上使用,因此无法用于该帐户。有什么方法可以覆盖该命名约定,以便我可以添加一个名为id_rsa的自定义键?

2 个答案:

答案 0 :(得分:0)

首先,尝试使用私钥没有密码:您将不必处理ssh-agent,这对于测试来说更容易。

第二,确保为old PEM format, not the new OpenSSH one生成一个私钥:

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

看看问题是否仍然存在。

您的堆栈跟踪还包括:

Authenticating to bitbucket.org:22 as 'eric'

请确保您的SSH URL为git@bitbucket.org,而不是 eric@bitbucket.org:密钥用于在会话中对您进行身份验证,但会话始终使用{{ 1}}帐户。

答案 1 :(得分:0)

我弄清楚是什么原因引起的。默认情况下,使用默认的git url(git@bitbucket.org:<username>/<repository>.git)时,bitbucket会查找名为“ id_rsa”的私钥。由于我的帐户已经绑定到另一个帐户,因此它不断抛出错误。但是,可以使用以下信息向帐户添加其他密钥:

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

为我工作,现在我可以通过SSH访问我的帐户。