一、问题描述
npm install 执行报错 fatal: Could not read from remote repository:
npm ERR! Error while executing:
npm ERR! d:\Program Files\Git\cmd\git.EXE ls-remote -h -t ssh://git@github.com/sohee-lee7/Squire.git
npm ERR!
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! D:\Program Files\nodejs\node_cache\_logs\2022-05-11T02_16_46_757Z-debug.log
12345678910111213
二、解决方法
原因是 GitHub 的客户端与服务端未生成 ssh key 或 ssh key 不匹配,需要重新生成。
1.生成新的SSH key
ssh-keygen -t rsa -C "youremail@example.com"
2.将 SSH key 添加到 GitHub 账户
选择 “Settings” –> “SSH and GPG keys” –> “New SSH key” ,将 id_rsa.pub 文件的密钥复制后填写进去:
3.验证 SSH key
使用 ssh -T git@github.com 对 SSH key 进行验证:
ssh -T git@github.com
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNICxxxxxIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
Hi xxxxx! You've successfully authenticated, but GitHub does not provide shell access.
123456