首页 > 其他分享 >【git】git配置两个gitlab和gitee账号和邮箱

【git】git配置两个gitlab和gitee账号和邮箱

时间:2022-11-25 11:58:13浏览次数:61  
标签:git gitlab rsa gitee ssh com id

转自:https://www.jianshu.com/p/2192e64a8e36

 

 

背景

由于公司使用gitlab部署私有代码库,个人有需求使用gitee的开源代码,
如果配置全局的账号密码会冲突。所以有必要生成两个id_rsa.pub密钥分别配置到gitlab和gitee的ssh密钥中去。

操作

  1. 设置第一个邮箱
ssh-keygen -t rsa -f ~/.ssh/id_rsa_1 -C “第1个邮箱”

如图所示,全程直接回车,不设置密码


  image.png
  1. 同理,设置第二个邮箱
ssh-keygen -t rsa -f ~/.ssh/id_rsa_1 -C “第2个邮箱”
  image.png
  1. 创建config文件
# first user
Host [email protected]
HostName http://gitlab.com
User 用户名
IdentityFile ~/.ssh/id_rsa_1

# second user
Host [email protected]
HostName https://gitee.com
User 用户名
IdentityFile ~/.ssh/id_rsa_2

这里配置过程中出现了一点问题,就是因为是公司gitlab,没有域名,这里需要在公司Gitlab的web版本创建一个空白项目,找到域名和端口


  image.png

这里将config文件改成:

# first user
Host 10.1.1.1(举例)
port 12345(举例)
HostName 10.1.1.1(举例)
User 用户名
IdentityFile ~/.ssh/id_rsa_1

# second user
Host [email protected]
HostName https://gitee.com
User 用户名
IdentityFile ~/.ssh/id_rsa_2
  1. 将id_rsa_1.pub和id_rsa_2.pub分别配置到gitlab和gitee的ssh密钥配置中。


      image.png
  2. 取消git的全局配置

git config --global --unset user.name

看一下有没有全局配置

git config --global -l

如图下图所示,如果没有用户名和邮箱就代表取消了全局配置了。


  image.png
  1. 执行ssh识别
    (1)#Start the ‘ssh-agent.exe’ process
eval $(ssh-agent -s)

(2)#install the SSH keys

ssh-add ~/.ssh/id_rsa_1
ssh-add ~/.ssh/id_rsa_2

(3)# show all id_rsa

ssh-add -l
  image.png

注意:
1、如果ssh-add这步报错:Could not open a connection to your authentication agent.
需要先启动ssh-agent,也就是上面的第一个步骤。
参考链接:https://stackoverflow.com/questions/17846529/could-not-open-a-connection-to-your-authentication-agent
2、如果执行ssh-add -l报错:Could not open a connection to your authentication agent.
需要先将密钥添加,也就是上述的第二步。
参考链接:https://stackoverflow.com/questions/26505980/github-permission-denied-ssh-add-agent-has-no-identities

  1. 测试是否连接成功


       


作者:Neil_Wong
链接:https://www.jianshu.com/p/2192e64a8e36
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

标签:git,gitlab,rsa,gitee,ssh,com,id
From: https://www.cnblogs.com/sammisammi/p/16924656.html

相关文章

  • Git命令 reset 和 revert 的区别
    前言在团队开发中,使用Git作为版本开发工具,可以便捷地协同多人管理并行开发,但是由于自己或者其他人代码提交污染了远程分支,就需要对远程代码进行恢复操作,Git提供了res......
  • 10、Git命令进行打包
    Git 基本操作、常用命令、代码打包及代码发布https://blog.csdn.net/qq_38487524/article/details/80305202 参考:Git打包文件:https://www.jianshu.com/p/1c2ddcb9d0......
  • 手把手教你用git上传项目到GitHub
    手把手教你用git上传项目到GitHub......
  • MFC-GetDlgItem获取控件句柄
          ......
  • Failed to resolve: com.github.*
    引入外部包时常见说要在项目根目录的build.gradle中添加allprojects{  repositories{    ......     maven {url'https://jitpack.io'}  }......
  • window10使用命令ssh工具生成github开源中国需要的ssh密钥以及转换为ppk让tortriseGit
    不知道大家用过putty没有,那个也可以生成,我以前生成很快的,现在不知道为什么,等待n久还是不行,如果把加密数缩短,还在github还用不了,还是用命令生成秒杀比较好。。ssh-keygen-......
  • 完美解决github访问速度慢和访问不通的问题
    Ghips工具,完美解决github访问速度慢和访问不通的问题。原理:自动获取GitHub最快IP,一键刷新hosts,这个小工具还是不错的,建议大家尝试下!尝试过很多方案,比如自己查询ip,修......
  • 2022年度GitHub中文Java项目排行榜Top 10
    1.mall项目地址:https://github.com/macrozheng/mallmall项目是一套电商系统,包括前台商城系统及后台管理系统,基于SpringBoot+MyBatis实现,采用Docker容器化部署。前台商......
  • 脚本上传typora图片到gitee
    用Gitee搭建图床,上传要用到Gitee的开放API:https://gitee.com/api/v5/swagger#/postV5ReposOwnerRepoContentsPath注意:Gitee的图片预览只能预览1M以内的图片,超过这......
  • 使用github、Packagist、composer发布
    下面我结合ThinkPHP来说一下怎么使用github和packagist在Windows环境下发布一个自己的composer包。1.首先需要加载windows版的composer,安装的时候需要注意必须开启php_opens......