当前位置:   article > 正文

git 多账户添加ssh秘钥

git ssh秘钥 多用户

生成秘钥的步骤:

  • ssh-keygen -t rsa -C "xxxx@qq.com"

添加秘钥

1226359-20190619160015144-1937541469.png

在不同的域中添加相同的秘钥是没有问题的,比如 github.com / code.aliyun.com

如果我想不同的域用不同的账号,或者同一个域有多个账号怎么办?

以上情况就需要生成多个秘钥

  • ssh-keygen -t rsa -C "xxxx@qq.com"
    回车,注意文件名需要修改,比如: id_rsa_qq
    另外两项直接回车

  • ssh-keygen -t rsa -C "xxxx@yahoo.com"
    回车,注意文件名需要修改,比如: id_rsa_yahoo
    另外两项直接回车

此刻文件生成好了,然后是配置

  • ssh-add ~/.ssh/id_rsa_qq
  • ssh-add ~/.ssh/id_rsa_yahoo

  • vim config 添加以下内容:

  1. # 配置code.aliyun.com
  2. Host code.aliyun.com
  3. HostName code.aliyun.com
  4. IdentityFile /root/.ssh/id_rsa_yahoo
  5. PreferredAuthentications publickey
  6. User xxxx@yaoo.com
  7. # 配置code.aliyun.com
  8. Host code.aliyun.com
  9. HostName code.aliyun.com
  10. IdentityFile /root/.ssh/id_rsa_qq
  11. PreferredAuthentications publickey
  12. User xxxx@qq.com
  13. # 配置github
  14. Host github.com
  15. HostName github.com
  16. IdentityFile /root/.ssh/id_rsa_github
  17. PreferredAuthentications publickey
  18. User xxxx@gmail.com

注意: 同一个域名的只有第一个有效

转载于:https://www.cnblogs.com/lanqie/p/11052068.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/671341
推荐阅读
相关标签
  

闽ICP备14008679号