用git作为代码版本控制,我们在clone代码的时候可以选择http协议,也可以使用ssh协议来拉取代码。
使用http协议的时候可以配置不要sslVerify
命令:git config http.sslVerify false
-
使用ssh协议 配置ssh key
- 打开
git bash
使用命令ssh-keygen -t rsa -C 'xxx@xxx.com'
生产ssh公钥和私钥对. (出现提示一直按回车)
- 打开
# ssh-keygen -t rsa -C 'jenkins@test.com'
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:bZUFUvPvPSTuSB45+UzC5AHhLf8wb911fH8s2OVJFdd jenkins@test.com
The key's randomart image is:
+---[RSA 2048]----+
| ...+.. |
| . o. = .|
| + .o .E |
| .+. .o.|
| S o* . +B|
| .+ Xo*=O|
| X.*o+O|
| o @ .o|
| o + |
+----[SHA256]-----+
- 打开
cat ~/.ssh/id_rsa.pub
将输出的内容拷贝
# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDzEAnTCwZJ1UpMd4sKuDmgS/46+om0RVrh+MIjW3UEv3ynjBCd8QhY3G3Ek6/gPG1UZc6HYtM2rmBhlqzP/eo6LrRm2R4yhgd2GuAjjjM6vr71kh/igrGaSNIKT9wXBAVKFx6ST6safl5Uch0XjaXoxygVL41qWFbv3WNjRiETpjG65tGO2aq8CrhKB3asLHpuEIxC9/+uKDwkxGHhbcnXzoi2pbX+2wZwQZkk32rC9H9arXfPJBeTwENfQ6fCLym02s9l7hvzNNsEeymanNvrKbO6R6R6WiZz/cKePpHhR+oLDF6D1FYN5Jn0c9GGRCl4WnqDUvuEZ3WgE/**P1kv jenkins@test.com
-
打开gitlab,找到Profile Settings-->SSH Keys--->Add SSH Key,并把上一步中复制的内容粘贴到Key所对应的文本框,在Title对应的文本框中给这个sshkey设置一个名字,点击Add key按钮. 如下图:
完成了gitlab配置ssh key ,就可以无密拉取和提交代码了。