【问题标题】:Reverting back to previous SSH public key恢复到以前的 SSH 公钥
【发布时间】:2021-11-01 07:38:07
【问题描述】:

我有两个帐户,一个在 GitLab 上,另一个在 GitHub 上。我已经准备好在 GitLab 上使用 SSH,但后来我想为 GitHub 推送一些东西,所以我按照 GitHub 上的 SSH 设置的分步说明进行操作,然后忘记了这件事。现在,当我尝试推送到旧 GitLab 存储库时,它给了我以下错误

Permission denied (publickey).fatal: Could not read from remote repository. Please make sure you have the correct access rightsand the repository exists.

【问题讨论】:

  • 确保您已注册 ssh 公钥并在本地提供您的私钥(安装在您的 ssh-agent 中)。如果您在为 github 创建新私钥时不小心删除/覆盖了您的 gitlab 私钥,则需要更改 gitlab 以使用该新公钥(或创建另一对并使用它——注意不要破坏您现有的私钥

标签: git github ssh gitlab


【解决方案1】:

检查~/.ssh 文件夹的内容。如果您只有一个 id_rsa(.pub) 密钥对,这意味着您已经用为 GitHub 生成的密钥覆盖了 GitLab 密钥。

为 GitLab 重新生成一个:

 ssh-keygen -t rsa -P "" -f gitlab

gitlab.pub 内容注册到您的 GitLab SSH 设置。

添加一个 ~/.ssh/config 文件:

Host gl
  Hostname gitlab.com
  User git
  IdentityFile ~/.ssh/gitlab

并使用以下命令更改您的远程 URL:

cd /path/to/local/gitlab/cloned/repository
git remote set-url origin gl:<me>/<myGitLabRepo>

【讨论】:

  • 在 .ssh 文件夹中,我找到了一个 id_rsa(.pub) paur 和另一个 id_ed#bunch_of_numbers#(.pub) 对。我还需要再生吗?
  • 哦,还有一个名为 known_hosts 的文件,它有 gitlab 站点、IP 和我猜在它的条目中的公钥。 Github 也在那里。
  • 我正在尝试篡改配置文件,现在一切都乱七八糟了,有没有办法重置整个东西?一种删除所有这些键并重新开始的方法?
  • @RetroCausalElectron 您可以保留您的 known_hosts 原样。但是 regenerate et 为 GitLab 注册一个新密钥,如答案中所述。您可以备份您的配置文件,然后使用我在答案中提到的内容从头开始。
猜你喜欢
  • 2020-05-30
  • 1970-01-01
  • 2016-01-06
  • 1970-01-01
  • 1970-01-01
  • 2015-06-01
  • 1970-01-01
  • 2011-04-10
  • 2021-11-08
相关资源
最近更新 更多