Git For Windows
在每次提交代码的时候都需要输入用户名和密码,为了节省时间和精力,我们应该设置一个SSH公钥
,这样就不用每次输入用户名和密码了。
具体步骤如下:
1、生成ssh密钥
cd ~/.ssh
使用 ssh-keygen
生成密钥
ssh-keygen -t rsa -C "your_email@example.com"
后面的三次输入均可使用默认值,Enter回车
跳过
密钥生成成功
Your identification has been saved in /home/you/.ssh/id_rsa.
Your public key has been saved in /home/you/.ssh/id_rsa.pub.
The key fingerprint is:
xxxxxxxxxxxxx your_email@example.com
# 查看公钥,复制备用
cat id_rsa.pub
ssh-rsa xxxxxxxxxxxxxx_your public rsa_xxxxxxxxxxxxxxxxxxxxxxxxx your_email@example.com
2、设置Git项目的ssh公钥,我这边是在Gitee上
注意:若此处设置错误,后面push
代码到远程仓库时会提示没有正确的访问权限
接着上面的添加公钥:
3、设置代码远程提交URL
下面这种Markdown语法,简书竟然不支持,目前用的这种语法:$\color{red}{红色字体内容} 显示不是很友好,只能勉强用了
<font color=#FF0000>若有其他Gitee上项目也需要使用SSH免密操作,移步至对应项目的.git所在目录下,将该项目的远程地址设为对应的ssh地址即可</font>
4、提交代码
省略git add
、git commit
等操作
已经不需要再输入用户名和密码了,至此Git For Windows 设置SSH公钥的操作就完成了,又能省点时间愉快的工(mo)作(yu)了。