Git学习02:解决Permission denied (publickey)问题—— GIT设置SSH key

 
问题:Permission denied (publickey).
 
viruser@fund-10-13-139 MINGW64 /d/workspace/tyj_file_backup (master)
$ git pull
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

 

原因分析:密钥设置不对
 
解决步骤
 
  1- 首先检查有没有在GitHub的https://github.com/settings/keys上添加你本机的SSH key。注意换了电脑是要重新添加的,每台都不一样。添加SSH key的方法:在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件,如果已经有了,可直接跳到下一步。如果没有,打开Shell(Windows下打开Git Bash),创建SSH Key:$ ssh-keygen -t rsa -C "youremail@example.com"你需要把邮件地址换成你自己的邮件地址,然后一路回车,使用默认值即可。如果一切顺利的话,可以在用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。
 
viruser@fund-10-13-139 MINGW64 /d/workspace/tyj_file_backup (master)
$ ssh-keygen -t rsa -C "my_email@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/viruser.v-desktop/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/viruser.v-desktop/.ssh/id_rsa.
Your public key has been saved in /c/Users/viruser.v-desktop/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:rhaMRZW+NFy9fvF50ZucR/PncIwhJ+YqEeELa8A6TCA myemail@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|       ... .     |
|E     . o . .    |
|.. . . + o   .  .|
|  . o o B   = +oo|
| o . = +S= + +.BO|
|  + . =.+   o +*O|
|   . . ... . . ++|
|      ... .     .|
|     ..  .       |
+----[SHA256]-----+
 
  2- 登陆GitHub,打开“Account settings”,“SSH Keys”页面:点“Add SSH Key”,填上Title,在Key文本框里粘贴id_rsa.pub文件的内容
 
 
  3-验证SSH Key是否添加成功
 
viruser@fund-10-13-139 MINGW64 /d/workspace/tyj_file_backup (master)
$ ssh git@github.com
PTY allocation request failed on channel 0
Hi tangyj5038! You've successfully authenticated, but GitHub does not provide  shell access.
Connection to github.com closed.

 

 END

 
 
posted on 2020-07-31 10:44  我不吃番茄  阅读(883)  评论(0编辑  收藏  举报