Multiple GitHub Accounts

Multiple GitHub Accounts

The post is also available on the author’s Personal Website : Multiple GitHub Accounts

Many a times you need to work with two different Github Accounts. If you are using macOs or windows, they save your account information and don’t give permissions to operate other accounts.

In order to run git commands for two different github accounts you need to follow the following step by step procedure.

Generating SSH Key for the account

ssh-keygen -t rsa -C "Github-email-address"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/aditya/.ssh/id_rsa): /Users/aditya/.ssh/id_rsa_aditya
Created directory '/Users/aditya/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/aditya/.ssh/id_rsa_aditya.
Your public key has been saved in /Users/aditya/.ssh/
The key fingerprint is:
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|   E ....     o.o|
|    ..o*o.  o..=.|
|     .+oS+.=.+ +.|
|    .     Oo+ . O|
|     o.  .** .   |
|      o=oX+.*    |
|     .=*O=+. .   |

Copy your SSH key using the command given below

pbcopy < ~/.ssh/

Now you need to add this key in your Github Account

Open GitHub -> Settings -> SSH and GPG keys -> New SSH Keys -> Copy the key -> Add SSH Key

Repeat the above steps for the second github account.

Setup Github Host

touch ~/.ssh/config

vi config
#first account
    User git
    IdentityFile ~/.ssh/id_rsa_aditya
#second account
Host github-raman
    User git
    IdentityFile ~/.ssh/id_rsa_raman
git init
git remote set-url origin git@github-raman:{ username } / { repository name with .git extension eg., aditya.git}

git config --global "{ your github email }"
git config --global "{ your github name }"

git status
git add --all
git commit -m "commit message"
git push

Thank you for being the patient reader. Please like and share this post

To read similar posts by the author please visit this site

Aditya Raman
Aditya Raman Software Developer | Engineer | Former Full Stack Developer Intern | Volunteer at UNV Online
comments powered by Disqus