How to manage multiple SSH key for Multiple Github Account

H

Recently I got a problem when trying to manage between my personal GitHub account and my GitHub work account. I usually use ssh to clone the remote GitHub repository and when the first time I tried to clone the repository from my work account, it’s still tried to pull using my personal ssh key instead of my work ssh key, even I already set it up.

Here’s what I tried to do to fix it :

  1. Make sure I already set up my work ssh key
  2. Create entry in ssh config file, this will be used for managing different GitHub account , for example , I use this one :
    Host github.com-personal
    User personal-account
    Hostname github.com
    PreferredAuthentications publickey
    IdentityFile /home/user/.ssh/id_rsa

    Host github.com-work
    User work-account
    Hostname github.com
    PreferredAuthentications publickey
    IdentityFile /home/user/.ssh/id_
    rsa_work
  3. When cloning the GitHub repo , change the GitHub URL to the ssh config host, for example:
    [email protected]:personal-account/personal-repo.git
  4. Configure the Git username and Email, for me I create a bash script to switch between my work account and personal account, since I using zsh, I create a simple bash script to export environment variable for bot account, and by default when I open my terminal it will configure to use my personal GitHub account

About the author

taffwarezz

Add comment

By taffwarezz