【问题标题】:Unable to connect using ssh on bitbucket无法在 bitbucket 上使用 ssh 进行连接
【发布时间】:2020-10-12 05:39:57
【问题描述】:

问题

我在从 bitbucket 推送拉取数据时遇到以下错误。

git fetch --all
Fetching origin
Forbidden
fatal: Could not read from remote repository.

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

我在 bitbucket 上的 ~/.ssh/project_ssh_key 和我的 ma​​c 上有相同的 ssh 密钥。

我试图解决的问题

我尝试使用以下命令创建一个新的 ssh 文件并使用它。

eval "$(ssh-agent -s)"
ssh-add -K ~/.ssh/my_project_new_private_key

我已经在 ** Personal Settings --> ssh keys ** 中的 bitbucket 中添加了新创建的密钥 并粘贴了公钥,但没有运气。

我也尝试了ssh -T git@bitbucket 并得到了输出

logged in as chakreshwar

You can use git or hg to connect to Bitbucket. Shell access is disabled

在我执行以下操作之前,一切都在使用旧密钥

1. I realized that my RoR application is not using **.ruby-version** & **.ruby-gemset**
2. I created a new gemset & use that gemset.
3. Move all the references from default to newly created gemset.
4. Bundle install and rails s to make sure everything works.

5. Delete all the old git branches from local which are no longer in use.

【问题讨论】:

  • 您能否运行git remote -v 并验证遥控器是否实际指向您要从中提取代码的位置?
  • 是的,没错

标签: ruby-on-rails git ssh bitbucket rvm


【解决方案1】:

首先检查您是否有~/.ssh/config 文件。

因为如果ssh -T git@bitbucket 有效,这意味着您有一个引用正确私钥的Host bitbucket 条目。

但在这种情况下, git remote -v 必须反映实际使用该主机条目的 SSH URL:

bitbucket:<me>/<myrepo>

(假设您的配置文件也有 User git 行)

不是bitbucket.org,而是bitbucket

所以:

cd /apth/to/local/repo
git remote set-url origin bitbucket:<me>/<myrepo>

【讨论】:

  • 正确,如果有主机 bitbucket 的条目,用户 = git,主机名 = bitbuket.org。它指向新创建的键
  • git remote -v 给出,git@bitbucket.org:username/myrepo.git,我现在应该尝试什么?
  • @ChakreshwarSharma 您应该将该远程 URL 更改为使用 SSH 配置文件指定的 URL:请参阅我编辑的答案。然后你可以 git pull 或 fetch。
  • 是的,它有效,在最后一行的答案中稍作更新,git remote set-url origin bitbucket:/,你忘了添加 origin
  • 还有一件事,我想问一下,如果我从配置文件中删除了条目并将 repo url 设置为 git@bitbucket.org:user/repo.git,它也应该可以工作
猜你喜欢
  • 1970-01-01
  • 2020-03-05
  • 2020-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-20
  • 2016-03-28
  • 1970-01-01
相关资源
最近更新 更多