gitlab,github,gitee公司私人两个账号同时配置使用

1. 查看当前git是否存在全局用户名邮箱

        git config  user.name

        git config  user.email

2. 如果已经设置全局用户名邮箱请先清除

        git config --global --unset user.name "你的名字"

        git config --global --unset user.email "你的邮箱"

3. 生成密钥

 A. 生成gitlab密钥一般是用你在公司用的邮箱,就是gitlab绑定的邮箱:

        ssh-keygen -t rsa -C "办公邮箱"

        点击回车会提示如下,你需要填写红色部分我用颜色标记

        Enter file in which to save the key (/c/Users/honey/.ssh/id_rsa): id_rsa_gitlab

B. 生成github密钥一般是用自己的邮箱,我常用qq邮箱邮箱:

        ssh-keygen -t rsa -C "qq邮箱"

        点击回车会提示如下,你需要填写红色部分我用颜色标记

        Enter file in which to save the key (/c/Users/honey/.ssh/id_rsa): id_rsa_gitlhub

C. 生成gitee密钥一般是用自己的邮箱,我常用qq邮箱邮箱:

        ssh-keygen -t rsa -C "qq邮箱"

        点击回车会提示如下,你需要填写红色部分我用颜色标记

        Enter file in which to save the key (/c/Users/honey/.ssh/id_rsa): id_rsa_gitee

4. 文件生成

此时在此目录下会生成如下文件:

  • id_rsa_github
  • id_rsa_github.pub
  • id_rsa_gitlab
  • id_rsa_gitlab.pub
  • id_rsa_gitee
  • id_rsa_gitee.pub

5. 文件拷贝

将这些文件全部拷贝到Windows .shh目录下,即:

C:\Users\Windows登录名\.ssh

6. 创建config文件

需要在.ssh文件夹下新建config文件,先新建config.txt,然后修改文件名去掉后缀。
config文件内容如下:
其中git.xxx.cn对应你使用的gitlab仓库地址

# gitlab
    Host git.xxx.cn
    HostName git.xxx.cn
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_gitlab
    User git
# gitee
    Host gitee.com
    HostName gitee.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_gitee
    User git
# github
    Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_github
    User git

7. 最后将各自的id_rsa.pub打开复制里面的公钥到对应的公钥添加里,添加前先删除原有的公钥,接下来就可以直接使用ssh拉取推送代码了

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值