Gitlab怎么使用ssh进行克隆

  1. 系统环境和软件环境查看
    系统环境
# cat /etc/redhat-release 
CentOS Stream release 9
# uname -a
Linux CentOSStream9Git215 5.14.0-381.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Oct 30 23:56:21 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

软件环境

# gitlab-rails console
--------------------------------------------------------------------------------
 Ruby:         ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-linux]
 GitLab:       16.5.1 (d59d7a49a1f) FOSS
 GitLab Shell: 14.29.0
 PostgreSQL:   13.11
------------------------------------------------------------[ booted in 57.47s ]
Loading production environment (Rails 7.0.8)
# git version
git version 2.39.3
  1. Gitlab服务器端设置ssh
    服务器端默认支持http进行克隆需要设置也允许ssh
    使用管理员登陆
    设置-通用-可见性与访问控制-启用Git访问协议
    image
    选择允许http和ssh
    image
    设置完成后打开仓库则会出现两个链接进行克隆一个ssh一个http
    image

  2. 客户端生成密钥
    客户端生成密钥

# ssh-keygen

使用默认一直回车即可

  1. Gitlbab服务器端设置密钥
    使用用户登录点击搜索或转到
    image
    搜索ssh
    image
    点击添加新密钥
    image
    把公钥 cat .ssh/id_rsa.pub复制到此处即可
    image
  2. 客户端克隆代码
    从项目代码复制克隆链接
# git clone git@ssh.192.168.3.215:liuym/lfs.git

注意:使用客户端克隆链接无法克隆 需要删除ssh
如下所示需要删除这个ssh字符
image
克隆完查看.git/config

# cat .git/config 
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
[remote "origin"]
	url = git@192.168.3.215:liuym/lfs.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
	remote = origin
	merge = refs/heads/main
[lfs]
	repositoryformatversion = 0
posted @ 2024-08-11 11:20  minseo  阅读(160)  评论(0编辑  收藏  举报