ssh key GitHub 验证不成功?来看看是不是这个原因

ssh key GitHub 验证不成功?来看看是不是这个原因

一、总结

一句话总结:

【Adding your SSH key to the ssh-agent】:忘记执行ssh-add id_rsa命令,会一直验证不成功

二、ssh key GitHub 验证不成功?来看看是不是这个原因

转自或参考:ssh key GitHub 验证不成功?来看看是不是这个原因
https://www.jianshu.com/p/be58fa27a704

使用ssh key验证github的好处就是不用每次提交代码的时候都要输入用户名和密码,因为着在一定程度上对效率有很大的影响,虽然这么做可以防止代码提交的次数过多,但这也看个人的习惯吧。

系统:macOS

打开控制台,建一个目录,比如~/.ssh(其实叫什么都无所谓,网上搜的基本上都这么配置)

在该目录下输入命令:
ssh-keygen -t rsa -C "youname@example.com"
注意:双引号换成自己的邮箱,如果遇到权限问题,只需在前面加上sudo

Generating public/private rsa key pair.
Enter file in which to save the key (/var/root/.ssh/id_rsa): ./id_rsa#这里填的是保存文件的路径
Enter passphrase (empty for no passphrase):#直接enter跳过 
Enter same passphrase again: #同上
Your identification has been saved in ./id_rsa.
Your public key has been saved in ./id_rsa.pub.
The key fingerprint is:
25:68:54:4a:f1:03:ab:78:15:3f:f7:9d:f0:bf:08:ee bsn.huang@gmail.com
The key's randomart image is:
+--[ RSA 2048]----+
|      *o.        |
|     o O         |
|      * * o .    |
|   . +   * . + . |
|  . o   S   . +  |
|   .           . |
|           .    .|
|          . . . .|
|          .E . . |
+-----------------+

这个时候,在.ssh目录下有两个文件

id_rsa        id_rsa.pub

其中id_rsa是私钥 id_rsa.pub是公钥
然后,执行下面的命令,将生成的key添加

#这条命令非常重要
ssh-add id_rsa 

然后将id_rsa.pub里面的内容复制下来,在github上的settings里面找到add keys,将其粘贴到key即可,title随便填
这个时候可以在控制台上测试一下

$ ssh -T git@github.com
The authenticity of host 'github.com (192.30.252.128)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/Users/Bsn/.ssh/known_hosts).
Hi bsnwong! You've successfully authenticated, but GitHub does not provide shell access.

其他不用管,只要看到最后一行,说明验证成功了
后话:刚开始忘记执行ssh-add id_rsa 命令,一直验证不成功,困在这里好久



 
我的旨在学过的东西不再忘记(主要使用艾宾浩斯遗忘曲线算法及其它智能学习复习算法)的偏公益性质的完全免费的编程视频学习网站: fanrenyi.com;有各种前端、后端、算法、大数据、人工智能等课程。
博主25岁,前端后端算法大数据人工智能都有兴趣。
大家有啥都可以加博主联系方式(qq404006308,微信fan404006308)互相交流。工作、生活、心境,可以互相启迪。
聊技术,交朋友,修心境,qq404006308,微信fan404006308
26岁,真心找女朋友,非诚勿扰,微信fan404006308,qq404006308
人工智能群:939687837

作者相关推荐

原文地址:https://www.cnblogs.com/Renyi-Fan/p/13812172.html