首页 > 解决方案 > Git 正在寻找错误的 SSH 密钥

问题描述

我决定尝试使用 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密钥?

标签: gitssh

解决方案


看起来我的 ~/.ssh/config 配置不当:

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

我需要将 IdentityFile 更改为真实文件,在我的情况下,id_rsa

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

推荐阅读