GitHub推送本地库到远程库报错Please make sure you have the correct access rights and the repository exists.

文章目录

  • 一、问题原因及报错展示
    • 1.原因
    • 2.报错展示
      • 2.1.第一次执行推送本地库到远程库命令报错(报错如下图所示)
      • 2.2报错后再次执行推送本地库到远程库命令还是报错(报错如下图所示)
  • 二、解决方法
    • 1.查看是否生成密钥(打开Git Bash执行下面命令)
    • 2.生成SSH密钥(打开Git Bash执行下面命令)
    • 3.查看公钥文件(根据生成SSH密钥提示查看公钥文件所在目录位置)
    • 4.将SSH公钥添加到GitHub

一、问题原因及报错展示

1.原因

  • 没有权限

Permission denied (publickey):权限被拒绝(公钥)

  • 出现这错误一般是以下两种原因:
    • 1.客户端与服务端未生成 ssh key
    • 2.客户端与服务端的ssh key不匹配

2.报错展示

2.1.第一次执行推送本地库到远程库命令报错(报错如下图所示)

GitHub推送本地库到远程库报错Please make sure you have the correct access rights and the repository exists._第1张图片

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])? 
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

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

2.2报错后再次执行推送本地库到远程库命令还是报错(报错如下图所示)

在这里插入图片描述

[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

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

二、解决方法

1.查看是否生成密钥(打开Git Bash执行下面命令)

ls -al ~/.ssh

在这里插入图片描述

此处可以看到一对文件,其中以.pub结尾的是公钥文件,另一个没有后缀的是私钥文件。

GitHub推送本地库到远程库报错Please make sure you have the correct access rights and the repository exists._第2张图片

2.生成SSH密钥(打开Git Bash执行下面命令)

  • github官方文档:https://docs.github.com/zh/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent?platform=windows
ssh-keygen -t rsa -b 4096 -C "邮箱号"

此处邮箱号为创建GitHub账号的电子邮件地址,途中会让你输入密码啥的,不用管,一路回车即可,则会生成SSH密钥(如果重新生成的话会覆盖之前的SSH密钥)。

GitHub推送本地库到远程库报错Please make sure you have the correct access rights and the repository exists._第3张图片

3.查看公钥文件(根据生成SSH密钥提示查看公钥文件所在目录位置)

GitHub推送本地库到远程库报错Please make sure you have the correct access rights and the repository exists._第4张图片

在这里插入图片描述

4.将SSH公钥添加到GitHub

  1. 登录GitHub,点击头像

    GitHub推送本地库到远程库报错Please make sure you have the correct access rights and the repository exists._第5张图片

  2. Settings

    GitHub推送本地库到远程库报错Please make sure you have the correct access rights and the repository exists._第6张图片

  3. SSH and GPG keys→New SSH key

    GitHub推送本地库到远程库报错Please make sure you have the correct access rights and the repository exists._第7张图片

  4. 复制公钥

    在这里插入图片描述

  5. 填写标题→粘贴公钥→Add SSH key

    GitHub推送本地库到远程库报错Please make sure you have the correct access rights and the repository exists._第8张图片

  6. 添加成功

    GitHub推送本地库到远程库报错Please make sure you have the correct access rights and the repository exists._第9张图片

  7. 推送本地库到远程

    GitHub推送本地库到远程库报错Please make sure you have the correct access rights and the repository exists._第10张图片

  8. GitHub查看推送内容

    GitHub推送本地库到远程库报错Please make sure you have the correct access rights and the repository exists._第11张图片

你可能感兴趣的:(github,git)