github上传shh公匙问题

鉴于问题少年的出发,刚刚把sno写成son卡了一个小时bug的我来了T T在上传代码到github总会遇到一系列问题,这次上传错误遇到公匙被拒绝的情况。

报错指令:

Administrator@ST2ZBMXGIN3TCED MINGW64 /f/idea-workspace/shirotest2 (master)
$ git push -u origin master
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

完整的解决过程:

首先初始化仓库

git init

其次上传所有文件到版本库中

git add .

查看版本库状态

git status

将版本库内的所有文件提交到缓冲区

git commit -m “first”

将本地仓库关联github远程仓库

git remote add origin git@github.com:moon-ice/shiroquick.git

讲缓冲区文件推送到远程仓库的master分支上(就是推到github上啦)

git push -u origin master

这时候问题就来啦,以往上面的步骤就能正常推送了,由于我重装过系统,C盘被我格式化了,github的密匙没了,报了以下错误

Administrator@ST2ZBMXGIN3TCED MINGW64 /f/idea-workspace/shirotest2 (master)

$ git push -u origin master

git@github.com: Permission denied (publickey).

fatal: Could not read from remote repository.

 

Please make sure you have the correct access rights

and the repository exists.

这时候新建密匙,输入这一串以后,按三个空格即可生成rsa密匙在我们电脑上

ssh-keygen -t rsa -C "1754716900@qq.com"
Generating public/private rsa key pair.

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

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in moonkey

Your public key has been saved in moonkey.pub

The key fingerprint is:

SHA256:GrIwtq8LaIxaessxSRFKPEZCW328lVC3M/iffLA4Vq8 1754716900@qq.com

The key's randomart image is:

+---[RSA 3072]----+

|=+... ..o...   |

|o=o. . o oo .   |

|o.o  . o. +   |

|  .  .  . o   |

|  = . . S  . o  |

|+o = o o   = =  |

|+o* . .   + = o |

|o=.+    . . o  |

|o.=+.     E  |

+----[SHA256]-----+

偶用的是win10系统,这个公匙文件在C:UsersAdministrator.ssh目录下

这里可以右键id_rsa.pub用记事本打开,把里面的内容复制

接下来是打开我们的github,新添加一把密匙

执行下面的操作,将密匙加进去

回到本地的git我们检查一下是否能连接上

ssh git@github.com

出现酱紫就没问题了~

Administrator@ST2ZBMXGIN3TCED MINGW64 /f/idea-workspace/shirotest2 (master)
$ ssh git@github.com
PTY allocation request failed on channel 0
Hi moon-ice! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

虽然偶前几次是这样的

Administrator@ST2ZBMXGIN3TCED MINGW64 /f/idea-workspace/shirotest2 (master)
$ ssh git@github.com
git@github.com: Permission denied (publickey).

最后愉快地扒拉TA,代码就传上去啦

git push -u origin master
Administrator@ST2ZBMXGIN3TCED MINGW64 /f/idea-workspace/shirotest2 (master)
$ git push -u origin master
Enumerating objects: 136, done.
Counting objects: 100% (136/136), done.
Delta compression using up to 12 threads
Compressing objects: 100% (121/121), done.
Writing objects: 100% (136/136), 72.13 KiB | 535.00 KiB/s, done.
Total 136 (delta 69), reused 0 (delta 0)
remote: Resolving deltas: 100% (69/69), done.
To github.com:moon-ice/shiroquick.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
原文地址:https://www.cnblogs.com/lightice/p/12595010.html