Github Multi Account
@ Author Name | Sunday, Oct 13, 2024 | 1 minutes read | Update at Sunday, Oct 13, 2024

You may have multiple github accounts (for whatever reason) and want to use all that in one machine. You may not realized (or you did?) that you can’t use same ssh key for multiple accounts, before you ask, I have answer for you, hear me out.

Prepare your keys

with ssh-keygen command, create another key with different name than your existing ones (for obvious reason)

Add your new key to your github account

Go to https://github.com/settings/keys and add your new ssh key there

Man of the show: git config on your machine

create new config file in this path ~/.ssh/config (config is the file here), with this kind of content:

# Default GitHub
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa
# New account
Host github.com-newaccount
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_newaccount

Adjust it as necessary, help yourself.

How to use it

for example, you want to clone react with your new account & key, do this:

git clone git@github.com-newaccount:facebook/react.git

That’s all, happy coding!

© 2024 Aditya Roshadi

Powered by Hugo with theme Dream.