git push遇到的问题“Please make sure you have the correct access rights and the repository exists.”

问题:今天在用idea往github推送代码的时候,出现了下面的报错

image-20230304171719329

原因:是ssh key有问题,连接不上服务器

解决:

1.得重新在git设置一下身份的名字和邮箱

git config --global user.name "yourname"

git config --global user.email "your@email.com"

说明:yourname是你要设置的名字,your@email是你要设置的邮箱。

2.删除.ssh文件夹(在C:\Users\某某某)下的known_hosts

3.git输入命令

ssh-keygen -t rsa -C "your@email.com"

your@email是你之前要设置的邮箱。

敲完命令按下回车后出现

Generating public/private rsa key pair.

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

再次按下回车

这时在.ssh文件夹下会生成两个文件,id_rsa和id_rsa.pub,打开id_rsa.pub,将里面的内容全选复制。

4.在浏览器登录你的github账号,进入设置,点击这一项

image-20230304172549453

image-20230304172618262

往key里面粘贴刚刚复制的内容,点击add ssh key.

image-20230304172724935

5.在git中输入下面的命令

ssh -T git@github.com

显示一些信息,输入yes,回车,提示你成功了。

最后退出git和idea,重新进入,往远程库push代码,发现成功了。

完。

参考:https://blog.csdn.net/jingtingfengguo/article/details/51892864

posted @ 2023-03-04 17:33  蜀道,难  阅读(238)  评论(0编辑  收藏  举报