当你第一次使用Git的clone
或者push
命令连接GitHub时,会得到一个警告:
The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is xx.xx.xx.xx.xx.
Are you sure you want to continue connecting (yes/no)?
这是因为Git使用SSH连接,而SSH连接在第一次验证GitHub服务器的Key时,需要你确认GitHub的Key的指纹信息是否真的来自GitHub的服务器,输入yes
回车即可。
Git会输出一个警告,告诉你已经把GitHub的Key添加到本机的一个信任列表里了:
Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
这个警告只会出现一次,后面的操作就不会有任何警告了。
如果你实在担心有人冒充GitHub服务器,输入yes
前可以对照GitHub的RSA Key的指纹信息 是否与SSH连接给出的一致。
解决第一次push或者clone出现的问题就需要配置sshkey设置你的电脑被git信任,方法如下
Github使用(配置SSHkey)
May 8, 2015
| 350 Hits
这一篇博客主要讲解怎么在windows环境下配置SSH key,以及添加到gubhub帐号中。官方教程传送门Generating SSH keys
SSH keys are a way to identify trusted computers, without involving passwords.
Step 1:检查电脑中是否已经有已存在的SSH key
首先我们需要检查电脑中已存在的SSH key,打开Git bash 输入下面命令:
1
2
3
yaohp
@Lenovo -PC MINGW64 ~/Desktop
$ ls -al ~/.ssh
ls: cannot access /c/Users/yaohp/.ssh: No such file or directory
报这个错,表示电脑不存在SSH key
如果电脑中存在SSHkey的话将会列出类似下面的目录结构
1
2
3
4
id_dsa.pub
id_ecdsa.pub
id_ed25519.pub
id_rsa.pub
~/. 表示当前目录,注意先cd 到当前 .ssh目录 然后再开始下面生成ssh key的步骤
Step 2:生成一个新的SSH key
在Git bash终端输入下面命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
yaohp
@Lenovo -PC MINGW64 ~/Desktop
$ ssh-keygen -t rsa -b
4096 -C
"youremail@qq.com"
Generating
public /
private rsa key pair.
Enter file in which to save the key (/c/Users/yaohp/.ssh/id_rsa) : filename
Enter
passphrase
(empty for no passphrase) :
Enter same passphrase again:
Your identification has been saved in filename.
Your
public key has been saved in filename.pub.
The key fingerprint is:
SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx youremail@qq.com
The key's randomart image is:
+---[RSA 4096]----+
| .. ..o...+|
| ..+ . . ..|
| ..o o . .|
| .E. . . . |
| ....S.+ . o |
| +. o+xxx =.|
| o . =.+.=+ =|
| =.+o=* |
| .===+o.|
+----[SHA256]-----+
出现上面这样就代表SSH key生成成功了,直接进入Step 3。
Step 3:登录git 设置ssh key
登录git账号点击头像进入个人中心---------》点击SSH and GPG keys------------>点击New SSh key
title随便写一个,然后key 的内容,则进入.ssh目录中打开刚才你生成的 xx.pub,复制里面的内容黏贴到key中保存
Step 4:测试连接
1
2
3
4
5
6
7
yaohp@Lenovo-PC MINGW64 ~
$ ssh -T git@github.com
Hi xxxxxxx! You've successfully authenticated, but GitHub does not provide shell access.
连接成功
参考链接:https://www.yaohepeng.com/2015/05/08/Github%E4%BD%BF%E7%94%A8%EF%BC%88%E9%85%8D%E7%BD%AESSHkey%EF%BC%89/