GitLab下载源码的两种方式(https/ssh-key)

news/2024/7/12 2:44:51 标签: ssh, https, git

如今很多公司使用git来作为代码版本控制工具,现所在公司是自己搭建私人的GitLab来管理代码的,GitLab中使用git clone下载源码时,支持httpsgit(即ssh)两种方式下载源码。

https://img-blog.csdnimg.cn/20200706171021362.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzM0NzE1NTg3,size_16,color_FFFFFF,t_70" width="450" />

一、使用https方式下载源码

这种方法在每次clone、pull、push等操作时都需要输入账号密码,如此十分繁琐。后来找到解决方案,就是在本地git客户端生成ssh-key,配置到GitLab去。

git clone https://.../sora.git

二、使用Git方式(ssh-key)下载源码

如果使用这种方法时,没配置SSH key,会报如下错误。

$ git clone ssh://git@ip:port/username/proj.git
Cloning into 'proj'...
git@ip: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

配置SSH证书的方法:

1. 使用ssh-keygen命令,生成ssh公钥和私钥对

点击回车,会让你选择存储路径,此时不用理会直接回车,其会保存到默认路径。

¥ssh-keygen

Generating public/private rsa key pair.
Enter file in which to save the key (/home/msy/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/msy/.ssh/id_rsa.
Your public key has been saved in /home/msy/.ssh/id_rsa.pub.
The key fingerprint is:SHA256:***************
The key's randomart image is:***************

2. 查看并复制公钥

cat /home/msy/.ssh/id_rsa.pub

type %userprofile%\.ssh\id_rsa.pub | clip
# 此时已复制

3. 配置GitLab

到GitLab界面,点击settings,后点击SSH-Keys,将复制过来的公钥粘贴到key框中,下方title可自己命名,点击addkey即可。

https://img-blog.csdnimg.cn/20200706174120278.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3NpbmF0XzM0NzE1NTg3,size_16,color_FFFFFF,t_70" width="1200" />


经过如上操作,再次拉取代码和提取代码应无需再输密码,若还需输入密码

      输入 git config --global credential.helper store  命令

      然后操作pull/push 会让输入用户名密码,第一次输入进去。下次再操作pull/push时就不需要输入用户名密码了。

参考文献:

git ssh key配置_讨厌走开啦-CSDN博客_git ssh


http://www.niftyadmin.cn/n/507184.html

相关文章

python递归_用python递归实现组合,以及关于递归的个人感想

上代码先: def fib(nlist,res): print_list [] print_list.extend(res) print_list.append(nlist if not nlist else nlist[0]) if len(nlist)1: print ‘#############print_list‘,print_list return temp_list [] temp_list.extend(nlist) for i in range(len(…

Caffe源码阅读(一)——caffe.proto

Protobuf是一种平台无关、语言无关、可扩展且轻便高效的序列化数据结构的协议,可以用于网络通信和数据存储。 Google Protocol Buffer(简称Protobuf)是Google公司内部的混合语言数据标准,用于RPC系统和持续数据存储系统。是一种轻便高效的可用于通讯协议…

用计算python两点之间的距离math_python计算两个地址之间的距离方法

我们调用高德地图的API来计算经纬度 #计算地址经纬度 import requests def geocode(address): parameters {address: address, key: cb649a25c1f81c1451adbeca73623251} base http://restapi.amap.com/v3/geocode/geo response requests.get(base, parameters) answer resp…

51单片机总结【引脚、时钟电路、复位电路、I/O端口、内部结构】

1、功能简述 STC89C52 是一种低功耗、高性能CMOS8位微控制器,具有8K在系统可编程Flash存储器(ROM)。STC89C52具有以下标准功能:8k字节Flash,512字节RAM,32位I/O 口线,看门狗定时器,2个数据指针&#xff0c…

VSCode 安装配置总结

引言 亲测 VSCode 安装合适的插件后,可以很方便地开发 C、Go、PHP、Python、Java、Lua、JS,一点不逊于Visual Studio、Goland、PHPStorm等。不过如果条件允许,建议 Java 最好还是使用 IntelliJ IDEA,Python 使用 PyCharm或Jupyte…

python连接mysql_Python连接Mysql常用的库(mysqlclient示例)

Python连接Mysql常用的库有MySQLdb,mysqlclient,MySQL Connector/Python,但是django文档上推荐使用mysqlclient,以下截取django官网关于MySQL API的介绍。 MySQL DB API Drivers The Python Database API is described in PEP 249…

I/O端口基础应用【LED:闪烁、流水灯、独立按键、数码管】

1、基础知识 电阻:102 10*10^21k ,25225*10^2 2500 LED接的电阻是限流电阻,VCC电压是5V,电流可能过大而烧毁LED灯,所以需要接一个限流电阻。 单片机是使用TTL电平,高5低0,所以控制单片机的P2口输出低电…