0

I have two ssh keys on my laptop: work.pub for work (and it is attached to my GitHub work account) and personal.pub (for personal usage and personal GitHub account). Also I am using macOS 11.0.1.

I have following .ssh/config:

Host *
   UseKeychain yes
   AddKeysToAgent yes
   IdentityFile ~/.ssh/personal
   IdentityFile ~/.ssh/work

I have added both ssh keys to Keychain with:

ssh-add -K ~/.ssh/work
ssh-add -K ~/.ssh/personal

Still, when I tried to push to personal repo on GH I get error than my_work_github_username does not allowed to push (here I expected that my personal ssh key would take precedence)

After it failed I deleted all identities from Keychain and tried to push one more time: ssh-add -D It pushed to personal .git, but with work identity (git commit showed my work avatar and nickname, but I was expecting it to show my personal pic and nickname)

What am doing wrong? How to be able to use multiple keys on one system?

Thanks!

Nikita Shchypyplov
  • 1,090
  • 1
  • 9
  • 18

1 Answers1

0

Starting with git 2.10, you can set a new configuration variable core.sshCommand. This specifies what value for GIT_SSH_COMMAND to use per repository.

See How to specify the private SSH-key to use when executing shell command on Git?

Rodrigo Murillo
  • 13,080
  • 2
  • 29
  • 50