一、问题描述
在git clone一个项目时出现如下报错:
(第一个选项,问你是否继续连接?输入yes然后回车)
The authenticity of host 'github.com (20.205.243.166)' 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,20.205.243.166' (ECDSA) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
通过报错信息可以看出,这是因为Github上没有本机的公钥导致的。
二、解决办法
1、在终端输入
ssh-keygen -t rsa -C "lycbuaacs@163.com"
其中双引号中填自己Github注册账号用的邮箱地址。
点击回车,看到提示
Generating public/private rsa key pair.
Enter file in which to save the key (/home/yichen/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/yichen/.ssh/id_rsa
Your public key has been saved in /home/yichen/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:KfhnvKTaASEb6Efb0LKofhCnu6rLgBX72FC3gRykSQU lycbuaacs@163.com
The key's randomart image is:
+---[RSA 3072]----+
| E++ |
| o +.o |
|. *+=.o |
|..oO*+ o . |
| oO+o.o S |
|o+.= o o |
|+ + o o = |
|+. . . * . |
|*=o ..o . |
+----[SHA256]-----+
说明:前三个冒号分别让你输入保存公钥的文件、一次性密钥和密钥确认,可以直接回车,他会默认创建密钥文件到指定路径下。看到如上图所示的乱码,说明公钥创建完成。
2、到路径下查看
我的路径是/home/yichen/.ssh/id_rsa.pub,(注意是后缀为.pub的文件,而不是id_rsa)
cat 显示文件内容,
cat /home/yichen/.ssh/id_rsa.pub
文件形式为
ssh-rsa 后面一堆字符
复制文件里的全部内容(包括前缀ssh-rsa)。文章来源:https://www.toymoban.com/news/detail-413680.html
3、打开GitHub
点击右上角自己头像,打开下拉菜单,选择设置Settings
左边找到SSH和PGP密钥,点击new SSH Key,将之前复制的内容粘贴到里面,就行了。
Title栏可以不填,密钥类型选择Authentication Key。
然后GitHub让你确认登录,确认登录后就大功告成,可以正常Git Clone了。文章来源地址https://www.toymoban.com/news/detail-413680.html
到了这里,关于git clone出现fatal: Could not read from remote repository解决办法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!