问题

去GitHub克隆仓库时报错:
 

(base) yhq@yhq-virtual-machine:~$ sudo git clone 
git@github.com:jbeder/yaml-cpp.git 正克隆到 'yaml-cpp'... 
The authenticity of host 'github.com (20.205.243.166)' can't 
be established. ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU. 
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' (ED25519) to the list of known hosts. git@github.com: Permission denied (publickey). 
fatal: 无法读取远程仓库。

错误原因是 使用 SSH 协议克隆仓库时,没有配置 GitHub 的 SSH 公钥。

解决方案

配置 SSH key(推荐,以后都能直接 git@github.com 克隆)

  1. 生成 SSH key(如果你没有的话):

    ssh-keygen -t ed25519 -C "你的GitHub邮箱"

    一路回车即可,默认会在 ~/.ssh/id_ed25519 下生成私钥和 id_ed25519.pub 公钥。

  2. 查看生成的公钥:

    cat ~/.ssh/id_ed25519.pub
  3. 登录 GitHub → Settings → SSH and GPG keys → New SSH key,把公钥粘贴进去。

  4. 测试是否成功:

    ssh -T git@github.com

    成功的话会提示:

    Hi <你的GitHub用户名>! You've successfully authenticated...
  5. 然后再执行:

    git clone git@github.com:jbeder/yaml-cpp.git

    就能克隆成功了。

(base) yhq@yhq-virtual-machine:~$ git clone git@github.com:jbeder/yaml-cpp.git
正克隆到 'yaml-cpp'...
remote: Enumerating objects: 9281, done.
remote: Counting objects: 100% (1929/1929), done.
remote: Compressing objects: 100% (459/459), done.
remote: Total 9281 (delta 1619), reused 1470 (delta 1470), pack-reused 7352 (from 2)
接收对象中: 100% (9281/9281), 4.95 MiB | 1.33 MiB/s, 完成.
处理 delta 中: 100% (6074/6074), 完成.

               

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐