GitLab配置添加SSH Key

工具 gitbash

1. 配置姓名 ,邮箱

  1. 配置姓名
$ git config --global user.name "rongyang"
  1. 配置邮箱
$ git config --global user.email "rong.yang@foxmial.com"

在这里插入图片描述

2. 客户端配置生成SSH密钥对

$ ssh-keygen -t rsa -C "rong.yang@woqutech.com"

在这里插入图片描述
完成后在 ~/.ssh/ 会生成2个文件。id_rsa 和 id_rsa.pub。前者是私钥,注意保管,后者是公钥。
查看 ssh 公钥方法:

1.通过命令窗口
a. 打开你的 git bash 窗口

b. 进入 .ssh 目录:cd ~/.ssh

c. 找到 id_rsa.pub 文件:ls

d. 查看公钥:cat id_rsa.pub 或者 vim id_rsa.pub

在这里插入图片描述
复制id.rsa.pub 到gitlab

3.添加SSH Key到GitLab

登录GitLab之后: Profile Settings => SSH Keys => Add SSH key

输入之前生成的公钥,标题自定义。

这样就行了。
在这里插入图片描述
在这里插入图片描述
公钥复制进去
在这里插入图片描述

如果是第二次创建公钥
尝试通过SSH连接时,我在下面收到此消息。

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
51:82:00:1c:7e:6f:ac:ac:de:f1:53:08:1c:7d:55:68.
Please contact your system administrator.
Add correct host key in /Users/isaacalves/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/isaacalves/.ssh/known_hosts:12
RSA host key for 104.131.16.158 has changed and you have requested strict checking.
Host key verification failed.

删除ssh文件的服务器地址就好了
在这里插入图片描述


版权声明:本文为weixin_44801506原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。