Mac 在使用git时, fatal: Could not read from remote repository.

参考文章博客。https://blog.csdn.net/u014702999/article/details/72783140

1 解决问题,获得SSH key

在使用git往远端puch代码的时候,有时候会出现一下的问题:

fatal: Could not read from remote repository.

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

出现这个问题时因为没有在github账号添加 SSH key。

解决方法如下:

  1. 在终端输入。
 ssh-keygen -t rsa -C "username"
     (注:username为你git上的用户名)

如果执行成功,返回

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/username/.ssh/id_rsa):

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/username/.ssh/id_rsa):

然后,在这里就是设置存储地址了.我们直接按回车,会出现一下两种情况的一种:

(1)如果正常运行的话,会出现

Enter passphrase (empty for no passphrase):

然后我们直接回车

(2)有的时候我们可能会出现

/Users/your username/.ssh/id_rsa already exists.

Overwrite (y/n)?

这说明你已经设置了存储地址,我们输入“y”覆盖
Overwrite (y/n)? y

回车

上面的情况之后 会出现在这里插入图片描述

这说明SSH Key 就已经生成了,文件目录就是/Users/slq/.ssh/id_rsa.pub.

此时我们执行cat 命令查看文件内容,

cat /Users/slq/.ssh/id_rsa.pub

把显示出来的SSH Keys 直接添加到github里面的SSH Keys

这样我们就获得了所要得到的ssh 很完美

把SSH Keys加入 github

接下来来讨论如何加入github的问题

  • 1 点击右上角的头像,选择Settings

在这里插入图片描述

  • 2 选择 SSH 选项

在这里插入图片描述

  • 3 选择后方的加入新的 SSH key
    在这里插入图片描述
  • 4 在这个页面输入 title 和key,这里的key就是刚刚从命令行复制过来的
    在这里插入图片描述
  • 5 添加就可以了
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值