5月 272019
新建仓库
在没有配置SSH密钥对之前,无法使用基于SSH的代码推拉操作。
You won’t be able to pull or push project code via SSH until you add an SSH key to your profile
为root用户准备SSH密钥(未设置私钥密码)
[root@client ~]# ssh-keygen -t ed25519 -C "harvey.mei@msn.com" Generating public/private ed25519 key pair. Enter file in which to save the key (/root/.ssh/id_ed25519): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_ed25519. Your public key has been saved in /root/.ssh/id_ed25519.pub. The key fingerprint is: SHA256:zZYLuVxm+EDjPAHGjlgJjTGdkw0hrjMwOuLs6r0rrnU harvey.mei@msn.com The key's randomart image is: +--[ED25519 256]--+ | =*oOo | | ..oO.o. | |o .o + + | |oo. . .+ B . | |B S O | |++ . @ . | | o. E o o | |.o.. | |B+.+o | +----[SHA256]-----+ [root@client ~]#
为私钥文件添加或者修改密码
ssh-keygen -p -o -f <keyname>
复制公钥内容到GitLab账户设置中
[root@client ~]# cat .ssh/id_ed25519.pub ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHWIgmnrN7FGjKTdMxYE3y6py3SKp5cO0wnc2dlWNj5o harvey.mei@msn.com [root@client ~]#
查看已导入的SSH公钥信息
测试用户root的SSH密钥有效性,按照提示将服务器端公钥存储在本地已知主机列表文件known_hosts文件中
[root@client ~]# ssh -i .ssh/id_ed25519 -T git@gitlab.licensebox.cn The authenticity of host 'gitlab.licensebox.cn (47.75.246.214)' can't be established. ECDSA key fingerprint is SHA256:s+kUB7fDvU43bDqTmukBOoSd/8o/gxzuQC/Kk1aYLio. ECDSA key fingerprint is MD5:f4:2a:7f:58:6c:d8:d3:ee:90:3a:14:9f:f9:5b:d4:4c. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'gitlab.licensebox.cn,47.75.246.214' (ECDSA) to the list of known hosts. Welcome to GitLab, @root! [root@client ~]#
查看保留在本地的服务器端
[root@client ~]# cat .ssh/known_hosts gitlab.licensebox.cn,47.75.246.214 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLPz49yrtFCwkwt+5/kCXekab8jtrEmf8OpPyfjqtoOuPMlHbhH/rnlNxcicFMF+0U9AD/RIigglJh5SFgSYQ3A= [root@client ~]#
本地操作系统安装Git客户端程序
[root@client ~]# git -bash: git: command not found [root@client ~]# yum -y install git
将仓库Clone到本地磁盘(无需再次验证身份)
[root@client ~]# git clone git@gitlab.licensebox.cn:root/licensebox.git Cloning into 'licensebox'... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0) Receiving objects: 100% (3/3), done.
查看本地Git目录及文件内容,确认成功Clone仓库至本地磁盘
[root@client ~]# ls licensebox [root@client ~]# ls licensebox/ README.md [root@client ~]# cat licensebox/README.md # licensebox LicenseBox Project[root@client ~]#