ruby-on-rails - 无法在 bitbucket 上使用 ssh 连接

标签 ruby-on-rails git ssh bitbucket rvm

问题

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

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 和 ma​​c 上的 ~/.ssh/project_ssh_key 上有相同的 ssh key 。

我曾尝试修复它

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

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

我已经在 ** 个人设置 --> ssh key ** 中添加了 bitbucket 中新创建的 key 并粘贴了公钥,但没有成功。

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

logged in as chakreshwar

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

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

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.

最佳答案

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

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

但在那种情况下,git remote -v 必须反射(reflect)实际使用该主机条目的 SSH URL:

bitbucket:<me>/<myrepo>

(假设你的配置文件也有一个 User git 行)

不是bitbucket.org,而是bitbucket

所以:

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

关于ruby-on-rails - 无法在 bitbucket 上使用 ssh 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62513096/

相关文章:

ruby-on-rails - 如果文件被删除,如何在 rspec 中进行测试?

git - 如何在 Git 中忽略目录中的文件?

c# - 仁慈SSH.NET : Is it possible to create a folder containing a subfolder that does not exist

ssh - 为什么 git push 不能选择正确的 ssh key?

ruby-on-rails - 通过后台作业插入/更新数据库,同时最大限度地减少读取影响

ruby-on-rails - 为什么这样的代码有效?

mysql - 最好的方法是什么......考虑性能

Git - 何时使用强制推送

git - 如何在不 merge 的情况下用另一个分支替换 Git 中的分支

git - 只获取提交历史记录?