Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to setup SSH keys for multiple Github accounts

📅 2019-Aug-27 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

Problem

A local Git repository can push and pull from a remote Github account using SSH authentication. This is typically configured by adding your SSH key to your Github account. If you have two or more Github accounts and try to use the same SSH public key for them, Github rejects the key with the error Key is already in use.

Solution

This problem can be solved by following these steps:

# Main Github host
Host github.com
    HostName github.com
    User git
    AddKeysToAgent yes
    IdentityFile ~/.ssh/id_rsa

# Second Github host
Host github.com-second
    HostName github.com
    User git
    AddKeysToAgent yes
    IdentityFile ~/.ssh/second_id_rsa

Tried with: Git 2.17.1 and Ubuntu 18.04