问题描述
问题 : 在使用git clone 项目的时候,出现报错,导致项目clone失败。
原因分析
原因 : 出现改问题的原因是git服务器没有存储本地ssh密钥。
解决办法:
一、设置git身份和邮箱
-
首先我得重新在git设置一下身份的名字和邮箱进入到需要提交的文件夹底下
git config --global user.name “yourname”git config --global user.email“your@email.com"
二、删除.ssh文件夹
- 删除.ssh文件夹(直接搜索该文件夹)下的known_hosts(手动删除即可,不需要git)
- 在下载好的Git中的bin目录下打开bash.exe输入命令
三、创建密钥
-
ssh-keygen -t rsa -C “username” (注:username为你git上的用户名),如果执行成功。
返回:
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/username/.ssh/id_rsa): //这里的username是电脑上的用户名,这个地址也是文件的存储地址,然后按回车, -
如果以前有存储地址会返回/Users/your username/.ssh/id_rsa already exists.Overwrite (y/n)?直接输入y回车。
-
如果以前没有储存地址就会出现Enter passphrase(empty for no passphrase);也直接回车,
-
两种情况回车后都会出现 Enter same passphrase again 然后接着回车会显示
The key’s randomart image is:
±–[RSA 2048]----+
| . . |
| . = . . o|
|o o * . . …|
|E oo o . o… |
| B . o S . … |
|. o o .o… |
| . o**. |
| .B=+%. |
| +*BoBo |
±—[SHA256]-----+,这说明SSH key就已经生成了。文件目录就是:username/.ssh/id_rsa.pub.
四、设置git添加密钥
-
然后系统会自动在.ssh文件夹下生成两个文件,id_rsa和id_rsa.pub,用记事本打开id_rsa.pub
-
打开https://github.com/,登陆你的账户,进入设置
点击add ssh key
五、再次尝试clone
-
在git中输入命令:ssh -T git@github.com
密码输入自己的登录密码 -
再次clone项目
成功!!!