为 bitbucket 帐户设置 ssh 密钥(使用 mac osx)

kal*_*gne 5 macos bitbucket ssh-keys ssh-agent

我有一个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.
Run Code Online (Sandbox Code Playgroud)

我做了以下事情:

$ 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
Run Code Online (Sandbox Code Playgroud)

然后我在我的 bitbucket 帐户的ssh keys 中添加了 my-key.pub 的内容。然后我重试克隆我的repository

$ 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.
Run Code Online (Sandbox Code Playgroud)

我在另一台机器上重复了相同的过程,它起作用了:

$ 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.
Run Code Online (Sandbox Code Playgroud)

我现在需要在我的第一台机器上做同样的事情。作为最后的手段,我使用 ssh-agent 在网上遵循了一些建议:

$ eval `ssh-agent -s`
$ ssh-add ~/.ssh/my-key
Run Code Online (Sandbox Code Playgroud)

但仍然没有运气:

$ 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.
Run Code Online (Sandbox Code Playgroud)

我不知道第一台机器有什么不同,为什么它拒绝我的请求?


编辑 1

当然,我尝试按照以下建议的非常基本的方式进行操作D.Samchuk

生成 id_rsa

$ ssh-keygen -t rsa
enterx3
Run Code Online (Sandbox Code Playgroud)

复制密钥的确切内容

$ cat ~/.ssh/id_rsa.pub
Run Code Online (Sandbox Code Playgroud)

我在我的 BitBucket 帐户的 ssh 密钥中添加了 id_rsa.pub 的内容。

Git clone 仍然不允许我访问存储库,输出错误消息与上面相同。


编辑 2

我不知道它可能与mac配置有关吗?由于另一台机器是redhat linux我只是想知道但找不到任何报告的类似问题。

小智 8

只需执行以下操作:

$ ssh-keygen -t rsa
Run Code Online (Sandbox Code Playgroud)

名称:id_rsa

密码:只需按两次 Enter 以避免每次连接时都打印关键字

$ cat ~/.ssh/id_rsa.pub
Run Code Online (Sandbox Code Playgroud)

复制输出

打开 bitbucket --> 配置文件 --> bitbucket 设置 --> 添加 ssh 密钥 --> 粘贴您的输出


kal*_*gne 0

解决了。当我深入研究这个问题时,我发现它绝对与密钥无关ssh,而是与错误消息所建议的缺少存储库有关。这一切都是为了使用git config --global弄乱我在那台计算机上的 git 配置来试验全局配置。我在另一个线程中详细介绍了我的步骤: https: //unix.stackexchange.com/questions/294780/git-retains-remote-information-from-a-deleted-repository/294809#294809