一台电脑配置多个平台【github, gitlab, gitee】

1. 生成ssh

进入到 .ssh目录下,

  1. cd ~/.ssh
  2. ssh-keygen -t rsa -C "邮箱名"
  3. # 因为要配置多个git故通过名称区别
  4. 如:github_id_rsa | gitlab_id_rsa | gitee_id_rsa

2.添加ssh到对应仓库

复制.pub文件的内容。到对应仓库配置完成。

  1. cat gitlab_id_rsa.pub

3.添加配置文件

  1. # 在.ssh文件夹下创建config文件
  2. touch config
  3. # 编辑config
  4. vim config
  5. #或者
  6. open config

内容如下

  1. # 配置github.com
  2. Host github.com
  3. HostName github.com
  4. IdentityFile ~/.ssh/github_id_rsa
  5. PreferredAuthentications publickey
  6. # 配置gitlab.com涉及到公司信息,故用***。请注意
  7. Host g.***.com
  8. HostName g.***.com
  9. IdentityFile ~/.ssh/gitlab_id_rsa
  10. PreferredAuthentications publickey
  11. # 配置gitee.com
  12. Host gitee.com
  13. HostName gitee.com
  14. IdentityFile ~/.ssh/gitee_id_rsa
  15. PreferredAuthentications publickey

设置介绍

  1. #网站的别名
  2. Host github.com
  3. # 托管网站的域名
  4. HostName github.com
  5. #指定优先使用哪种方式验证, 支持密码和秘钥验证方式
  6. PreferredAuthentications publickey
  7. # 托管网站上的用户名,可以不设置
  8. User gitlab@126.com
  9. # 使用的密钥文件。要用绝对路径。
  10. IdentityFile ~/.ssh/id_rsa

4.测试是否配置成功

  1. ssh -T gitlab.com
  2. ssh -T github.com