Git push提交时报错Permission denied(publickey)...Please make sure you have the correct access rights and the repository exists.

一、git push origin master 时出错
错误信息为: Permission denied(publickey).

fatal: Could not read from remote repository.

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

可能:
可能没联网
可能没配置好.git/conf文件
可能是与github上的账号没建立密钥对

二、解决办法
配置文件: 进入你的仓库,下面有个.git目录里面有conf配置文件,直接vim .git/conf 修改成如下:如果不是git提交是https方式,url和pushurl自己改成自己仓库的地址就好
 11 
 12 [remote "origin"]
 13     url = git@github.com:s--enten--/--an.git
 14     fetch = +refs/heads/*:refs/remotes/origin/*
 15     pushurl = git@github.com:s--enten--/--an.git.git
 16 [branch "master"]
 17     remote = origin
 18     merge = refs/heads/master  

建立密钥:

  1. ssh-keygen -t rsa -C "youremail@example.com"

    注意,上述youremail@example.com是指github账户的注册邮箱

  2. ssh -v git@github.com

    上述命令执行后,出现的提示最后两句是

    No more authentication methods to try.

    Permission denied (publickey).

  3. ssh-agent -s

    上述命令执行后,出现的提示最后两句是

    SSH_AUTH_SOCK=/tmp/ssh-GTpABX1a05qH/agent.404; export SSH_AUTH_SOCK;

    SSH_AGENT_PID=13144; export SSH_AGENT_PID;

    echo Agent pid 13144;

  4. ssh-add ~/.ssh/id_rsa

    上述命令执行后,出现提示

    Identity added: . . . (这里是一些ssh key 文件路径)

    Could not open a connection to your authentication agent.

  5. 若第4步中出现上述提示,则执行此步骤,否则执行6

    eval 'ssh-agent -s'

    ssh-add ~/.ssh/id_rsa

  6. vim ~/.ssh/id_rsa.pub

    上述命令执行后id_rsa.pub文件内容将输出到终端,复制里面的密钥(内容一般是以ssh-rsa 开头,以github账号的注册邮箱结尾的,全部复制下来)

  7. 进入github账号,在settings下,选SSH and GPG keys, 点击new SSH key
    以下可参考这篇博客

posted @   G1733  阅读(549)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示