解决拉取多个不同git项目下的ssh问题

目录

一、情况背景

二、私钥不匹配报错

三、密钥生成

        3.1、单git仓库生成

        3.2、多git仓库生成


一、情况背景

        简单来讲,就是不同的git仓库需要有对应不同的ssh私钥。公钥需要在git仓库的ssh页面配置后,才能正常的提交拉取仓库代码。否则会因为公钥不匹配而报错。一般来说,git仓库的ssh key的配置在:我的—settings—ssh key。

二、私钥不匹配报错

        如若私钥和git仓库配置的公钥不匹配,那么就无法进行拉取提交代码。使用idea等工具操作远程git仓库,那么git console会输出如下图的报错。

        一般出现这种情况的大概率是同时使用了两种及以上的git仓库,如github和gitlab。解决方法就是生成两份公钥和私钥即可,然后再去对应的git ssh页面进行配置。

git clone xxxx
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:0ga5tdL1I49aoKBp0qwakGwnO9/YAyiW9XPw4oCHYqk.
Please contact your system administrator.
Add correct host key in /c/Users/dell/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /c/Users/dell/.ssh/known_hosts:3
ECDSA host key for xxx.xx.x.xx has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

三、密钥生成

        3.1、单git仓库生成

1、cmd打开输入:ssh-keygen -t rsa -C "xxxx@qq.com" 后,一直回车直至看到如下内容。
The key's randomart image is:
+---[RSA 3072]----+
|          ...    |
|     .   . o     |
|    E o.o o      |
|     o.o+.o.     |
|    . ooSBo*     |
|   o .. o=O .    |
|    o. .o*.+     |
|     ..o=+* o .  |
|   .o.o=**=oo+   |
+----[SHA256]-----+
2、进入 C:\Users\dell\.ssh 查看对应的公钥私钥,其中id_rsa为私钥,id_rsa.pub为公钥。
3、复制公钥(id_rsa.pub)到git仓库的ssh页面进行配置。

        3.2、多git仓库生成

        如若需要使用多git仓库来管理代码,那么需要生成多个公钥私钥来对应。本文就拿两个(github、gitlab)仓库举例。

ssh-keygen -t rsa -C "xxx@qq.com"
ssh-keygen -t rsa -f c:\users\dell\.ssh\id_rsa.github -C "xxx@163.com"


c:\users\dell\.ssh 
    id_rsa
    id_rsa.pub
    id_rsa.github
    id_rsa.github.pub
拷贝对应的公钥(.pub文件)到git仓库的ssh配置页面中进行配置。

相关推荐

  1. 解决不同git项目ssh问题

    2024-04-30 09:50:02       13 阅读
  2. Windows配置账号git ssh

    2024-04-30 09:50:02       33 阅读
  3. Git同时和推送分支

    2024-04-30 09:50:02       15 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-30 09:50:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-30 09:50:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-30 09:50:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-30 09:50:02       20 阅读

热门阅读

  1. 【Python快速上手(四)】

    2024-04-30 09:50:02       15 阅读
  2. 【Golang】Gin 框架的多种类型绑定函数

    2024-04-30 09:50:02       13 阅读
  3. Android Room 数据库中的 Journal mode 解释

    2024-04-30 09:50:02       13 阅读
  4. 【Spring AI】07. 提示词

    2024-04-30 09:50:02       11 阅读
  5. Verilog学习之时序控制、语句块(1)

    2024-04-30 09:50:02       12 阅读
  6. Caddy实践 | Docker环境下使用Caddy快速部署web服务器

    2024-04-30 09:50:02       11 阅读
  7. memcpy,memmove函数详解

    2024-04-30 09:50:02       15 阅读
  8. 云容器与云中间件

    2024-04-30 09:50:02       11 阅读