Home > Blockchain >  Unable to Git clone with a second personal github account
Unable to Git clone with a second personal github account

Time:01-29

I have added a second github account on my laptop in addition to the first one. The document https://betterprogramming.pub/how-to-use-multiple-github-accounts-with-one-computer-c9ba3f851b75 did help a lot but I am facing issues while cloning a repo which is accessible from the second github account.

I generated the keys id_rsa_unaccount and id_rsa_unaccount.pub and added the content of id_rsa_unaccount.pub to my ssh field in the second github account.

>ls ~/.ssh  
config          id_rsa          id_rsa.pub      id_rsa_unaccount    id_rsa_unaccount.pub

Updated the ~/.ssh/config

# Account 1 (work or personal) - the default config
Host github.com
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa

# Account 2 (personal) - the config we are adding
Host github-unaccount
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa_unaccount

Also setup

git config user.name "Gupastha" 
git config user.email "asthagupta92 [email protected]"

However when I tried to git clone the repo, I see

git clone git@github-unaccount:Noble-Missions/itakeactions.git 
Cloning into 'itakeactions'...
ERROR: Repository not found.
fatal: Could not read from remote repository.

I also went through multiple stack overflow links for the same but I couldnt find a solution to the cloning yet. Can anyone please nudge me?

CodePudding user response:

Check first if your second key is recognized:

ssh -Tv github-unaccount

No need for git@ since it is included in your ~/.ssh/config

Then use, assuming Linux-like environment:

export GIT_SSH_COMMAND='ssh -v'
git clone github-unaccount:Noble-Missions/itakeactions.git 

You will see what keys are considered during the clone operation.

The OP Astha Gupta confirms the wrong key is used because, from the comments:

I had an additional entry in the ssh config: Host *, which was pointing to id_rsa.

  •  Tags:  
  • Related