在
Ubuntu 20.04 上,使用 GitHub 上的
Ed25519 密钥,即使运行了
ssh-keygen -R github.com
命令并按照
主要答案 的建议操作,每次运行
git push
命令时仍然会看到这些通知:
$ git push
Warning: the ECDSA host key for 'github.com' differs from the key for the IP address '140.82.112.4'
Offending key for IP in /home/gabriel/.ssh/known_hosts:14
Matching host key in /home/gabriel/.ssh/known_hosts:15
Are you sure you want to continue connecting (yes/no)? yes
Warning: the ECDSA host key for 'github.com' differs from the key for the IP address '140.82.112.4'
Offending key for IP in /home/gabriel/.ssh/known_hosts:14
Matching host key in /home/gabriel/.ssh/known_hosts:15
Are you sure you want to continue connecting (yes/no)? yes
Warning: the ECDSA host key for 'github.com' differs from the key for the IP address '140.82.112.4'
Offending key for IP in /home/gabriel/.ssh/known_hosts:14
Matching host key in /home/gabriel/.ssh/known_hosts:15
Are you sure you want to continue connecting (yes/no)? yes
所以,我最终通过将~/.ssh/known_hosts
文件重命名来删除它:
(尝试使用@bk2204的答案而不是运行下面的mv
命令。感谢@Guntram Blohm)。
mv ~/.ssh/known_hosts ~/.ssh/known_hosts.bak
...现在git push
终于又可以正常工作了!我不介意每次使用SSH连接到特定服务器时都必须重新验证所有我的SSH目的地,因此有效地删除~/.ssh/known_hosts
文件是可以接受的。反正我几乎只用SSH来推送到GitHub和GitLab。
注意:在那之后第一次运行git push
时,我必须输入yes
,如下所示:
$ git push
The authenticity of host 'github.com (140.82.112.4)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,140.82.112.4' (ECDSA) to the list of known hosts.
Everything up-to-date
在输入yes
之前,我首先在GitHub的网站上验证了SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM
指纹是否正确,并从GitHub获取了每个密钥类型的指纹。GitHub在此处提供了每个密钥类型的指纹:https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints
这些是GitHub的公钥指纹:
SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s
(RSA)
SHA256:br9IjFspm1vxR3iA35FWE+4VTyz1hYVLIE2t1/CeyWQ
(DSA - 已弃用)
SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM
(ECDSA)
SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU
(Ed25519)
ssh-keygen -R github.com
- 这个命令不会更新以前的 ssh 密钥(您的~/.ssh/id_rsa
和~/.ssh/id_rsa.pub
保持不变)。 - Constantin De La Roche