I'm having some issues juggling two different SSH keys on my machine. I have two GitHub accounts with distinct usernames and ssh keys.
I have a private directory on my GitHub @ zshap/test-push
and mysteriously, when I change the readme and push it up, I'm seeing commits from my zackshapiro user, who is not a collaborator and has not been invited to that repo.
I don't understand how my other user would even be able to push to the private repo of zshap.
For good measure, the accounts have different profile pictures as well so it's easy to identify that zackshapiro has pushed to the zshap repo.
Also for good measure, I use these aliases to set my ssh key in terminal:
alias ssh-personal="ssh-add -D; ssh-add -K ~/.ssh/key1"
alias ssh-zshap="ssh-add -D; ssh-add -K ~/.ssh/key3"
Also for good measure, I've deleted the SSH key, key2
, and created a new key3
using GitHub's tutorial in case I'd accidentally uploaded an existing key to GitHub. Additionally, I've ensured that the signatures shown in the SSH and GPG Keys section of GitHub settings are all different.
My ~/.ssh/config
:
Host zackshapiro
HostName github.com
User git
IdentityFile ~/.ssh/key1
IdentitiesOnly yes
Host zshap
HostName github.com
User git
IdentityFile ~/.ssh/key3
IdentitiesOnly yes
Host *
AddKeysToAgent yes
UseKeychain yes
This is very confusing and the other answers to how to use multiple ssh keys on one machine don't seem to address this particular case. I'd love some help here so I'm not crossing these wires.
Thanks!
Edit
If I run ssh -T
, I get a correct username here so it's extra strange that the commits are coming from my other user and ssh key
$ ssh -T git@github.com
Hi zshap! You've successfully authenticated, but GitHub does not provide shell access.
Edit 2
In my foo
repo directory, I can run ssh-personal
and then git push
to push a new commit and I get the error (correctly):
ERROR: Repository not found. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Then when I run ssh-zshap
and git push
, I can successfully push but the commit message is from the wrong user! It's by the zackshapiro GitHub user instead of the zshap user.