githubssh-keysed25519multiple-accounts

Github default account is not working after changing for multiple accounts


I have used my office github account. But i was need to add my personal github account also. My office github account is dinukafrost. My personal github account is dinuka.

I did following steps.

  1. Create ssh keys. (I have already had ssh key for office account)
  2. Add public keys to github. (My office public key was added)
  3. Create ~/.ssh/config file.

My ssh keys.

id_ed25519_dinuka  
id_ed25519_dinukafrost  
id_ed25519_dinukafrost.pub  
id_ed25519_dinuka.pub

My config file

PubkeyAcceptedKeyTypes=+ssh-rsa

# dinukafrost

Host github.com
 HostName github.com
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/id_ed25519_dinukafrost

# dinuka

Host dinuka github.com
 HostName github.com
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/id_ed25519_dinuka

These command are given correct response.

āžœ  ssh -T git@github.com
Hi dinuka! You've successfully authenticated, but GitHub does not provide shell access.
āžœ  ssh -T git@dinuka    
Hi dinuka! You've successfully authenticated, but GitHub does not provide shell access.

Now i can use my personal account with dinuka host. eg - origin git@dinuka:dinuka/laravel_test.gi

But i can't use my office repos that i was using. eg - origin git@github.com:MyCompany/lp-service-registry.git

It is throwing following error

ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

How can i fix this issue. Is any way to find any logs for fixing this?


Solution

  • ssh -T git@github.com
    Hi dinuka!
    

    That means a github.com entry authenticates you with your personal account.
    Probably because of the entry Host dinuka github.com, instead of Host dinuka

    I prefer using entries with a specific name rather than "github.com".
    (And I always include User git, to avoid the git@ part of the SSH URL).

    PubkeyAcceptedKeyTypes=+ssh-rsa
    
    # dinukafrost
    
    Host github.com
     HostName github.com
     PreferredAuthentications publickey
     IdentityFile ~/.ssh/id_ed25519_dinukafrost
    
    # dinuka
    
    Host dinuka
     HostName github.com
     PreferredAuthentications publickey
     IdentityFile ~/.ssh/id_ed25519_dinuka
     User git
    

    Check if ssh -Tv github.com does authenticate you as dinukafrost.
    If not, replace Host github.com with Host dinukafrost, and repeat the test with ssh -Tv dinukafrost.