1、在机器上执行ssh-keygen命令,生成公私钥;生成的时候会提示文件保存路径,以及私钥密码,直接回车就行;

pi@raspberrypi:~/Desktop $ ssh-keygen -t rsa -C '***@qq.com'  #这里填写自己的邮件
Generating public/private rsa key pair.
Enter file in which to save the key (/home/pi/.ssh/id_rsa): 
Created directory '/home/pi/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/pi/.ssh/id_rsa
Your public key has been saved in /home/pi/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:WsYlwYbcuInvHFk46+lmY/Ax0+s+T7+GnNVGnthCO8o guobingbing@huanuo.com.cn
The key's randomart image is:
+---[RSA 3072]----+
|     . =.        |
|      + +.       |
|     . =. .      |
|    . =..o  . .  |
|     . *S  . B . |
|    . O+.   * *  |
|     *.* +.= +   |
|      @ o.E..    |
|     =.+oo..o.   |
+----[SHA256]-----+

2、找到生成的公钥文件,默认是在~/.ssh目录下

pi@raspberrypi:~/Desktop $ cd ~/.ssh
pi@raspberrypi:~/.ssh $ ls
id_rsa  id_rsa.pub

3、将id_rsa.pub中的内容复制到gitlab中的个人设置,ssh密钥的文本框中,点击新增即可;

4、在本地机器上执行 git clone 测试通过;

git clone git@192.168.1.7:project/demo.git

发表评论