最近在服务器Linux系统下git clone遇到如下问题:
Could not read from remote repository.

问题原因:git上没有创建SSH Key

解决办法:
1.生成SSH密钥

ssh-keygen -C “邮箱” -t rsa

下面会应用到密钥的存放位置,这里是:/root/.ssh/id_rsa

2.登录个人github添加客户端生成的公钥
打开Settings,点击SSH and GPG keys,点击New SSH Key:

标题自己添加即可,Key中粘贴id_rsa.pub(/root/.ssh/id_rsa.pub)公钥文件中的内容:

cat id_rsa.pub

在这里插入图片描述

3.将key加入到ssh-agent

ssh-add ~/.ssh/id_rsa

如果在此处遇到Could not open a connection to your authentication agent,请点击这里

4.初始化git仓库
创建一个git仓库,进入目录后输入

git init


可以在刚创建的仓库中测试一下SSH Key

ssh -T git@github.com


出现you‘re successful,即为成功。
5.clone github仓库上的代码到本地,OK

git clone xxxxxxxx


如果是在使用git提交代码时出现 fatal: Could not read from remote repository
首先,将本地生成的 id_rsa以及id_rsa.pub这两个文件删除掉。

rm id_rsa
rm id_rsa.pub


然后,使用命令 ssh-keygen -t rsa -C "邮箱地址"重新生成密钥。

ssh-keygen -C “邮箱” -t rsa


最后,将id_rsa.pub文件里的内容复制到你的github的SSH key选项下即可。
 

Logo

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

更多推荐