如何在极狐GitLab中添加 SSH Key?

本文分享如何生成 SSH Key 并添加到极狐GitLab 中,然后用 SSH Key 进行代码拉取。

极狐GitLab 是 GitLab 在中国的发行版,可以私有化部署,对中文的支持非常友好,是专为中国程序员和企业推出的企业级一体化 DevOps 平台,一键就能安装成功。安装详情可以查看官网指南

SSH Key 对于通过 ssh 来进行极狐GitLab 代码拉取是重要的,完成整个流程一般分为三步:

  • SSH Key 的生成
  • 添加 SSH Key 到极狐GitLab 中
  • 使用 ssh 克隆代码

第一步:生成 SSH Key

使用 ssh-keygen命令来生成 SSH Key:

复制代码
ssh-keygen -t rsa -C "jh-gitlab@devops.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa_jh_gitlab
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa_jh_gitlab
Your public key has been saved in /root/.ssh/id_rsa_jh_gitlab.pub
The key fingerprint is:
SHA256:OuX13mP/EASg/KljuZXrWsq65WIvzFaU9T72tXisVPc jh-gitlab@devops.com
The key's randomart image is:
+---[RSA 3072]----+
|          ...    |
|       . ..  .   |
|        oo .  .  |
|        o. ...   |
|       .S +.  ...|
|       +.+ o+ ..+|
|     oo.B +..++.E|
|      B* * o.o+= |
|     oo*Boo .o+o+|
+----[SHA256]-----+

生成之后,可以在 ~/.ssh目录下面查看:

复制代码
ls -ltr ~/.ssh/
total 24
-rw------- 1 root root  676 Apr  3 14:49 authorized_keys
-rw-r--r-- 1 root root  284 Sep  5 14:15 known_hosts
-rw-r--r-- 1 root root  574 Sep  5 14:16 id_rsa_jh_gitlab.pub
-rw------- 1 root root 2610 Sep  5 14:16 id_rsa_jh_gitlab

可以看到最下面两个是刚才生成的 SSH Key pair。pub 是公钥,另外一个是私钥。可以用 cat命令查看两个 key 的内容。

第二步:将 SSH Key 添加到极狐GitLab

点击左上角的头像 --> 偏好设置 --> SSH 密钥

点击右上角的添加新密钥:

将第一步中生成的 pub 内容拷贝到密钥方框中,然后可以自定义标题,选择到期时间,直接点击添加密钥即可完成 SSH Key 的添加。

第三步:clone 仓库代码

添加完 SSH Key 就可以使用 ssh 来 clone 代码了:

复制代码
git clone git@jhma.jihulab.net:root/kubernetes-agent.git
Cloning into 'kubernetes-agent'...
remote: Enumerating objects: 21, done.
remote: Total 21 (delta 0), reused 0 (delta 0), pack-reused 21 (from 1)
Receiving objects: 100% (21/21), 4.09 KiB | 838.00 KiB/s, done.
Resolving deltas: 100% (2/2), done.
相关推荐
友莘居士5 小时前
软件研发如何选对方法论?传统计划驱动与敏捷价值驱动的全面对比
devops·敏捷·传统·软件研发方法论
一念一花一世界5 小时前
DevOps实战(4) - 使用Arbess+GitLab+SourceFare实现Java项目自动化部署
gitlab·tiklab·arbess·开源cicd工具·sourcefare
赵孝正6 小时前
GitLab 分支管理与 Push 问题全解析
大数据·elasticsearch·gitlab
wjs0401 天前
Git常用的命令
java·git·gitlab
至善迎风1 天前
版本管理系统与平台(权威资料核对、深入解析、行业选型与国产平台补充)
git·gitee·gitlab·github·svm
高旭的旭1 天前
Gitlab 配置自定义 clone 地址
svn·ssh·gitlab·code
一念一花一世界1 天前
DevOps实战(3) - 使用Arbess+GitLab+Hadess实现Java项目自动化部署
gitlab·jenkins·tiklab·arbess·开源cicd工具
小薛博客2 天前
17、DevOps持续集成、持续部署
运维·ci/cd·devops
faimi2 天前
🚀程序员必收藏!最全Git命令手册:解决90%团队协作难题
前端·gitlab
rivercoder2 天前
Gitea:轻量级的自托管Git服务
git·gitlab·gitea