sourceTree配置ssh key
2018-10-17 本文已影响0人
吖蛋黄
一、使用 git 客户的生成公私钥:id_rsa、id_rsa.pub
1、设置Git的user name和email
$ git config --global user.name "xxx"
$ git config --global user.email "xxx.mail@xxx.com"
2、检查是不是已经存在密钥(能进去说明已经存在,就删掉文件夹,重新创建):
cd ~/.ssh
3、生成 SSH 密钥,打开命令行终端输入ssh-keygen -t rsa -C <your_email@example.com>
( 你的邮箱),连续点击 Enter 键即可。
C:\Users\HASEE>ssh-keygen -t rsa -C "danhuanhong@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\HASEE/.ssh/id_rsa):// 推荐使用默认地址
Created directory 'C:\Users\HASEE/.ssh'.
Enter passphrase (empty for no passphrase)://此处点击 Enter 键即可,也可以填写密码,填写密码后每次使用 SSH 方式推送代码时都会要求输入密码,由于这个 Key 也不是用于军事目的,所以也无需设置密码。
Enter same passphrase again:
![](https://img.haomeiwen.com/i6166110/2b539ae86a7ec5e6.png)
![](https://img.haomeiwen.com/i6166110/d9f42f1c695060f4.png)
二、设置 SourceTree 的 SSH客户端
1、配置SourceTree 的 SSH 客户的为:OpenSSH
1.1 工具->选项
![](https://img.haomeiwen.com/i6166110/4cd64139dc1a445c.png)
1.2 SSH客户端配置,选择OpenSSH
![](https://img.haomeiwen.com/i6166110/0f428cebcc3a5c93.png)
三、coding项目里面,部署公钥>新建部署公钥,把C:\Users\HASEE.ssh\id_rsa.pub的内容复制到公钥内容中。
第一种:全局秘钥,对账号的所有项目有效
![](https://img.haomeiwen.com/i6166110/c76dac1a5c1a8cd2.png)
![](https://img.haomeiwen.com/i6166110/1d76f06637b8c57c.png)
第二种:项目秘钥,只对改项目有效
![](https://img.haomeiwen.com/i6166110/18424ebe5e40f14b.png)
![](https://img.haomeiwen.com/i6166110/d2293b8688ecc3fb.png)
四、配置好SSH秘钥后,拉取项目时,注意选择SSH协议的链接。
![](https://img.haomeiwen.com/i6166110/5611eea7f6f9b674.png)
五、成功
![](https://img.haomeiwen.com/i6166110/edf78ab488587f8d.png)