2

So I have two different github accounts and I've created two different SSH keys for them id_me and id_work, however when I try to make a git push from to my work account, it authenticates me with my personal SSH key instead.

This what I've done:

Added each SSH key to its respective github account. Then followed the steps to add them to my SSH agent:

ssh-add -K id_me
ssh-add -K id_work

And set up my ~/.ssh/config like this:

# Personal github account
Host github.com
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_me

# Work github account
Host github.com-work
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_work

I'm trying to make some changes to a repo on my work account. First, I make sure to clone it using the proper command:

git clone [email protected]:test.git

However, when I push the changes back up, it throws a permission denied error msg:

ERROR: Permission to test.git denied to doctopus.
fatal: Could not read from remote repository.

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

Also, I notice that when I run ssh -T github.com-work, it authenticates me on my personal account:

Hi doctopus! You've successfully authenticated, but GitHub does not provide shell access.

So the issue looks like git is not using the right SSH key when it pushes to github.

3
  • Are you sure the host name is correct ? github.com-work Commented Mar 11, 2021 at 17:04
  • You'll need IdentitiesOnly yes so that ssh doesn't send all identities, but only the ones listed under github.com-work. You may have other settings that need adjustment too. Until ssh -T github.com-work identifies you as your work name, it's getting your home-public-key; poke around to figure out why. Commented Mar 11, 2021 at 22:10
  • Thanks @torek, your suggestion worked Commented Mar 12, 2021 at 12:41

1 Answer 1

2

ssh -Tv github.com-work will display which key is actually used.

That way, you can validate your ~/.ssh/config content.

Double-check the content of the public key registered to your GitHub account, as well as the content of both public keys (id_work.pub and id_me.pub)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.