Git在寻找错误的SSH密钥。

11

我决定尝试使用SSH来处理我的GitHub仓库。我修改了git/.config中的远程URL,现在它使用SSH:

[remote "origin"]
        url = git@github.com:keddad/passpoint_server.git
        fetch = +refs/heads/*:refs/remotes/origin/*

但是当我运行 git fetch 命令时,Git会查找错误的密钥:

(venv) keddad@keddad-pc:~/PycharmProjects/passpoint_server/.git$ git fetch
no such identity: /home/keddad/.ssh/github_rsa: No such file or directory
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

同时,真正添加到GitHub上的关键是在文件 ~/.ssh/id_rsa 中。 如何让git使用 id_rsa 密钥?

2
~/.ssh/config 存在吗?也许密钥是在其中为 GitHub 配置的。 - ElpieKay
@ElpieKay 是的! 我不知道它是如何配置的,但它被配置成这样了。谢谢。 - keddad
2个回答

12

试试这个:

ssh-add ~/.ssh/correct_key

9

看起来我的~/.ssh/config配置得不太好:

Host github.com
  IdentityFile ~/.ssh/github_rsa
  IdentitiesOnly yes

我需要将IdentityFile更改为一个真实的文件,对于我的情况来说,是id_rsa

Host github.com
      IdentityFile ~/.ssh/id_rsa
      IdentitiesOnly yes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接