fatal: “Could not read remote” -- Mac下使用Git Push显示权限错误

我昨天在提交项目的时候遇到了这个问题:

在终端输入git push origin master 这条命令时 终端显示
《fatal: “Could not read remote” -- Mac下使用Git Push显示权限错误》

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

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

这个问题的出现主要是 我的SSH key被我重新覆盖了一遍 但是github上面没有添加这个SSH key

所以我搜索了网上的解决方法,如下:

在终端输入: ssh-keygen -t rsa -C “AndIMissU”
这条命令的“”里面填写的是自己GitHub的用户名

终端出现:

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

按下回车

终端出现:

/var/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y

输入y回车

终端出现:

Enter passphrase (empty for no passphrase): 

按下回车

终端显示:

Enter same passphrase again: 

最后回车出现:

Your identification has been saved in /var/root/.ssh/id_rsa.
Your public key has been saved in /var/root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:7emPWueS2x2NHFIliv2E65vDsO9KLZo5JHwytj8aRQs AndIMissU
The key's randomart image is:
+---[RSA 2048]----+
|              . .|
|           o o o |
|      E . . + o  |
|       o o   =   |
|     .  S . o o  |
|      *.o..+ o + |
|     ..B  *=+ + .|
|      ..oB+*o+ . |
|      .o*+=BO..  |
+----[SHA256]-----+

我们可以看到 我们的SSH key就存放在 /var/root/.ssh/id_rsa.pub目录下
然后我们需要查看一下 SSH key
在终端中输入 cat /var/root/.ssh/id_rsa.pub(这里的cat 后面加的是你自己存放的SSH key 的路径)下面的就是我的路径:
《fatal: “Could not read remote” -- Mac下使用Git Push显示权限错误》

此时cat 输入以后 出现 你要的SSH key
《fatal: “Could not read remote” -- Mac下使用Git Push显示权限错误》

然后:打开GitHub的Settings 添加一个新的SSH key

《fatal: “Could not read remote” -- Mac下使用Git Push显示权限错误》

最后一步:复制刚刚cat到的SSH key 添加进入下面的红色框框内 这样我们就可以正常的push和pull啦

《fatal: “Could not read remote” -- Mac下使用Git Push显示权限错误》

    原文作者:IMissU
    原文地址: https://segmentfault.com/a/1190000012141565
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞