生成多个SSH

  1. ssh-keygen -t rsa -C 'xxxxx@company.com' -f ~/.ssh/gitee_company_id_rsa
  1. ssh-keygen -t rsa -C 'xxxxx@qq.com' -f ~/.ssh/github_qq_id_rsa
  1. ssh-keygen -t rsa -C 'xxxxx@qq.com' -f ~/.ssh/gitlab_id_rsa

在 ~/.ssh 目录下新建一个config文件,添加如下内容

  1. # gitee 主账号
  2. Host gitee.com
  3. HostName gitee.com
  4. PreferredAuthentications publickey
  5. IdentityFile ~/.ssh/gitee_company_id_rsa
  6. User xxxxx@company.com
  7. # gitee xylim
  8. Host gitee.xylim.com
  9. HostName gitee.com
  10. PreferredAuthentications publickey
  11. IdentityFile ~/.ssh/github_qq_id_rsa
  12. User xxxxx@qq.com
  13. # gitlab私服
  14. Host git.hzlim.cn
  15. HostName git.hzlim.cn
  16. PreferredAuthentications publickey
  17. IdentityFile ~/.ssh/gitlab_id_rsa
  18. User root
  19. Port 2222

命令测试

  1. ssh -T git@gitee.com
  2. ssh -T git@gitee.xylim.com
  3. ssh -T git@git.hzlim.cn

克隆gitee.xylim.com账号的仓库代码

设置提交代码的信息

  1. git config remote.origin.url git@gitee.xylim.com:xylim/homework.git