linux从github上拉取项目到本地遇到Permission denied (publickey). fatal: Could not read from remote repository.

问题

中意的项目拉取到本地碰到如下提示:

Permission denied (publickey).
fatal: Could not read from remote repository.

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

则你想clone的可能是一个private项目。这种情况就需要在linux上配置密钥。

解决方案

linux生成ssh密钥

ssh-keygen -t rsa -C 邮箱

在这里插入图片描述
下面的提示如果不知道设置什么的话都可以使用默认值,即一路Enter向下

若上面使用的是默认地址,则进入

cd /root/.ssh

如果填写过保存密钥的地址则进入自己填写的地址

查看密钥:

cat id_rsa.pub

复制其中的内容,以便稍后在github上添加

github上添加密钥

提供两种设置方式,其中后一种比较靠谱,不想fork该项目可以跳过第一种方式。

首先在github上fork该项目。然后进入项目设置Setting,在左边菜单中选择Secrets:
在这里插入图片描述
右边选择New repository secret,在Value中粘贴上一步生成的密钥:
在这里插入图片描述
Name可以随意填写,Add secret以后即可使用下述命令拉取:

git clone 项目的ssh克隆地址

如果上述步骤执行完以后仍报相同错误,尝试添加ssh key:进入个人setting-》左侧菜单栏点选SSH and GPG keys-》New SSH key-》名字随便起,内容填写上述生成文档中的内容。再次使用命令拉取即可
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44559752/article/details/109851961
今日推荐