window配置git的ssh登录

前言
这篇文章主要介绍
window系统如何配置ssh,让git去用ssh的方式进行登录。
开发环境:window


尝试拉取代码

拉取代码:git clone git@gitee.com:ou_yanting/test.git

提示如下

1
2
3
4
5
6
7
8
9
10
Cloning into 'test'...
The authenticity of host 'gitee.com (180.97.125.228)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com,180.97.125.228' (ECDSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

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

生成ssh密钥

输入以下命令:ssh-keygen -t rsa -C "这里写你的邮箱",然后无脑回车就是啦。
当出现以下代码代表生成成功了!

1
2
Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.

查看生成的密钥

查看生成的密钥,并且复制:cat ~/.ssh/id_rsa.pub

添加密钥

  • 打开gitlab的密钥链接https://gitee.com/profile/sshkeys(需要先进行注册登录)。
  • 将刚刚复制的密钥,粘贴到公钥的文本框当中,标题就会自动填充,点击确定即添加成功了(标题可以随便改哈)。
    ps:其它代码管理平台的添加公钥也是大同小异的,我这里就不一一列举了。

再次尝试拉去代码

拉取代码:git clone git@gitee.com:ou_yanting/test.git
出现以下代码即表示成功:

1
2
Cloning into 'test'...
warning: You appear to have cloned an empty repository.

ps:我这里是空的git项目,所以会提示empty。假如你的git有代码/文件是否拉去成功应该也能自己判断吧~

总结

其实clone代码还有种异常情况的,我现在重现不了了(手动狗头)。



window配置git的ssh登录
作者
墨陌默
发布于
2020年3月6日
许可协议