# Git 设置多个 SSH Key

By [cryptoshine.eth](https://paragraph.com/@cryptoshine) · 2022-06-09

---

生成两个ssh密钥
---------

    ssh-keygen -t rsa -C 'xxxxx@xxx.com' -f ~/.ssh/id_rsa_key1
    
    ssh-keygen -t rsa -C 'xxxxx@xxx.com' -f ~/.ssh/id_rsa_key2
    

在 ~/.ssh 目录下config文件添加
----------------------

    Host github1
    HostName github.com
    User key1
    IdentityFile ~/.ssh/id_rsa_key1
    
    Host github2
    HostName github.com
    User key2
    IdentityFile ~/.ssh/id_rsa_key2
    

ssh 测试
------

    ssh -T git@github.com
    

\*\*成功返回：\*\*Hi key! You've successfully authenticated, but GitHub does not provide shell access.

在github SSH keys或Deploy keys 添加.pub 公钥
--------------------------------------

![SSH and GPG keys](https://storage.googleapis.com/papyrus_images/385aff373a4f7eeeb78fa18c7fe044ad36bf30c1a03571b1d1ba5c12fc10ae57.png)

SSH and GPG keys

在项目目录下设置邮箱和用户名
--------------

    git config user.name "key1"
    git config user.email "xxxxx@xxx.com"
    
    ssh-add ~/.ssh/id_rsa_key1
    

完结
--

---

*Originally published on [cryptoshine.eth](https://paragraph.com/@cryptoshine/git-ssh-key)*
