为Bitbucket账户设置SSH密钥(使用Mac OS X)

6

我有一个 BitBucket 帐户。尽管在计算机上设置了 ssh key 并将其添加到我的 bitbucket 帐户中,但我无法连接:

$ git clone git@bitbucket.org:my-account/myrepo.git 
Cloning into 'myrepo'...
conq: repository does not exist.
fatal: Could not read from remote repository.

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

我做了以下操作:

$ cd ~/.ssh

$ ssh-keygen -f ~/.ssh/my-key -N ''

$ vim config
Host bitbucket.org
  HostName bitbucket.org
  IdentityFile ~/.ssh/my-key

$ ls -l
-rw-------  1 me  ...   229 Jul  8 15:50 config
-rw-------  1 me  ...  1679 Jul  8 14:07 my-key
-rw-r--r--  1 me  ...   411 Jul  8 14:07 my-key.pub

我将 my-key.pub 的内容添加到我的 Bitbucket 账户的 ssh key 中。然后我重试克隆我的存储库:

$ git clone git@bitbucket.org:my-account/myrepo.git 
Cloning into 'myrepo'...
conq: repository does not exist.
fatal: Could not read from remote repository.

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

我在另一台机器上重复了相同的操作,它成功了:

$ git clone git@bitbucket.org:my-account/myrepo.git
Initialized empty Git repository in /home/me/.ssh/myrepo/.git/
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

我现在需要在我的第一台机器上进行相同的操作。 作为最后的办法,我按照网上的一些建议使用ssh-agent:
$ eval `ssh-agent -s`
$ ssh-add ~/.ssh/my-key

但仍然没有运气:
$ git clone git@bitbucket.org:my-account/myrepo.git 
Cloning into 'myrepo'...
conq: repository does not exist.
fatal: Could not read from remote repository.

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

我不知道第一台机器有什么不同,为什么会拒绝我的请求?
编辑1:
当然,我尝试了最基本的方法,就像D.Samchuk建议的那样:
生成id_rsa。
$ ssh-keygen -t rsa
enterx3

复制密钥的确切内容

$ cat ~/.ssh/id_rsa.pub

我已将 id_rsa.pub 的内容添加到我的 BitBucket 账户的 ssh 密钥中。

使用 Git clone 仍无法访问存储库,并显示与上述相同的错误消息。


编辑2

我不知道可能与 Mac 配置有关吗?因为另一台机器是 redhat linux,所以我想知道但找不到任何报告类似问题。


1
我投票关闭此问题,因为它与编程无关。请尝试https://apple.stackexchange.com。 - Droppy
我同意你的观点,对造成的麻烦感到抱歉。 - kaligne
3个回答

15

只需按照以下步骤操作:

$ ssh-keygen -t rsa

名称:id_rsa

密码:按两次回车键以避免每次连接时打印关键字。

$ cat ~/.ssh/id_rsa.pub

复制输出

打开 Bitbucket --> 个人资料 --> Bitbucket 设置 --> 添加 SSH 密钥 --> 粘贴您的输出


这是我尝试创建自己的配置文件和单独的SSH密钥之前做的第一件事。尽管我删除了我的SSH密钥和配置文件,但我按照您的步骤操作后,“git clone”仍然无法让我访问存储库,出现相同的错误。 - kaligne
这个不起作用。我只是按照官方指南 https://support.atlassian.com/bitbucket-cloud/docs/set-up-personal-ssh-keys-on-macos/ 做的。 - vovahost

1

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接