git 多賬戶添加ssh秘鑰


生成秘鑰的步驟:

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

添加秘鑰

在不同的域中添加相同的秘鑰是沒有問題的,比如 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

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM