Home > Software design >  on MAC Monterey, git clone working but git push fails because it uses wrong ssh key on push?
on MAC Monterey, git clone working but git push fails because it uses wrong ssh key on push?

Time:02-05

My ~/.ssh/config has this entry

Host personal
   HostName github.com
   IdentityFile ~/.ssh/id_ed25519personalgithub
   IdentitiesOnly yes

I git clone with

git clone git@personal:deanhiller/testwithexecutor-all.git

That works fine. My .git/config file has it correct like so

[remote "origin"]
    url = git@personal:deanhiller/testwithexecutor-all.git
    fetch =  refs/heads/*:refs/remotes/origin/*

When I git push however, I get this error

dean@Deans-MacBook-Pro testwithexecutor-all % git push
ERROR: Permission to deanhiller/testwithexecutor-all.git denied to deancompanyuser

It is using the wrong username and not the username deanhiller!!! Why is this?

If I do a git config -l, I have no user name set (desired so I can easily just work out of repositories without screwing around cloning and pushing very easily). I do not want to keep changing usernames or having to set the username every time I clone a repo. Where is it even grabbing deancompanyuser from???

CodePudding user response:

The user deancompanyuser is very likely saved on your Keychain Access. So open the Keychain Access on your Mac and search about "GitHub" and remove the entry. After that, it should no longer show the wrong user.

CodePudding user response:

First, add User git in your config file:

Host personal
   HostName github.com
   User git                                     <=====
   IdentityFile ~/.ssh/id_ed25519personalgithub
   IdentitiesOnly yes

That way, you can clone with personal:... instead of git@personal.
And you can test which user is authenticated with that key using ssh -Tv personal (instead of ssh -Tv git@personal)

Second, id_ed25519personalgithub.pub has been registered to the deancompanyuser's account, not deanhiller's.
As a result, deancompanyuser does not have the right to push to a repository they do not own.

But it can clone deanhiller's repository, if said repository is a public one.

  •  Tags:  
  • Related