GitLab 免密操作

518 阅读1分钟

概述

GitLab 免密操作通常指的是使用 SSH 密钥对实现与 GitLab 仓库之间的无密码交互,包括克隆、拉取、推送等操作。

配置

  1. 生成秘钥
ssh-keygen -t rsa -C "abc"

Generating public/private rsa key pair.
Enter file in which to save the key (/home/huo-l/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/huo-l/.ssh/id_rsa
Your public key has been saved in /home/huo-l/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:eJe4oYncVLRijYEWGTjUgDco+dxGo4vw3uM3hx6FLrk abc
The key's randomart image is:
+---[RSA 3072]----+
| =o+o=. .        |
|= = B  = .       |
|.+ B .+ +        |
|. + o. = . .     |
|.o o  + S o      |
|. o. * = +       |
| . .= *..        |
|  . oo+..        |
|   .E+.o         |
+----[SHA256]-----+

一路回车,使用默认值就好。 2. 在 ~ 目录下新建文件 .gitconfig

[user]
        email = xxx@126.com
        name = xxx
[credential]
        helper = store
[http]
        sslVerify = false
  1. 在 ~ 目录下新建文件 .git-credentials
# 保存配置 例:http://zhangsan:1234567@gitlab.com
http://[用户名]:[密码]@gitlab的域名
  1. 执行命令
git config --global credential.helper store
  1. 复制公钥文件
more ~/.ssh/id_rsa.pub
  1. 登录账号,设置秘钥

20240301-110609.jpg

复制公钥到红色框中,点击 添加秘钥

20240301-110851.jpg

如图所示,添加成功

20240301-111027.jpg

测试

测试拉取,是否还需要账号密码