生成秘钥的步骤:

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

添加秘钥

git 多账户添加ssh秘钥

在不同的域中添加相同的秘钥是没有问题的,比如 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 添加以下内容:

# 配置code.aliyun.com     
Host code.aliyun.com                
    HostName code.aliyun.com
    IdentityFile /root/.ssh/id_rsa_yahoo
    PreferredAuthentications publickey
    User xxxx@yaoo.com

# 配置code.aliyun.com     
Host code.aliyun.com                
    HostName code.aliyun.com
    IdentityFile /root/.ssh/id_rsa_qq
    PreferredAuthentications publickey
    User xxxx@qq.com

# 配置github
Host github.com                
    HostName github.com
    IdentityFile /root/.ssh/id_rsa_github
    PreferredAuthentications publickey
    User xxxx@gmail.com

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

相关文章:

  • 2021-08-25
  • 2021-12-03
  • 2021-12-12
  • 2021-06-17
  • 2022-12-23
  • 2021-06-05
  • 2022-02-10
  • 2021-09-28
猜你喜欢
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2021-11-28
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案