恢复到以前的SSH公钥



我有两个账户,一个在GitHub上,另一个在GitLab上。我在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文件夹的内容。如果你只有一个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>

最新更新