【问题标题】:Git is not using the correct SSH key to autheticate [closed]Git没有使用正确的SSH密钥进行身份验证[关闭]
【发布时间】:2021-09-24 14:33:27
【问题描述】:

我在两个主机中有两个存储库。我最近在 GitHub 中配置了 ssh github 正在工作,但不是“其他”。所以我将密钥添加到 ~/.ssh/config 如下。

Host other
    HostName other.host
    IdentityFile ~/.ssh/id_rsa
    User git

Host github
    HostName github.com
    IdentityFile ~/.ssh/id_ed25519
    User git

但是现在,对“其他”的 git 操作有效,但对 GitHub 无效。

我试过了

我删除了know_hosts 文件并重试。似乎 ssh 正在为“github.com”使用id_rsa 密钥

$ git pull
The authenticity of host 'github.com (140.82.121.4)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?yes
Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
s1n7ax@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我尝试重启 sshd

sudo systemctl restart sshd.service

【问题讨论】:

  • Host githubgithub.com 不匹配。

标签: git ssh


【解决方案1】:

请注意,当您声明配置主机条目时,这些条目现在是您的 URL 的一部分。

在你的情况下:

cd /path/to/local/repo
git remote set-url origin github:<me>/<myrepo>
                          ^^^^^^

您需要使用您在~/.ssh/config 中设置的确切Host 字符串:它是ssh -i ~/.ssh/id_ed25519 git@github.com 的快捷方式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-04
    • 2012-11-11
    • 2020-02-21
    • 1970-01-01
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    相关资源
    最近更新 更多