I have more than one user on github and today for some reason github decided to use the other user that normally I don’t use. Probably it happened because I removed the SSH keys from my main user (let say user_a). But I don’t remember removing the SSH keys and yesterday everything was working normally.
So, then I tried to run:

$ git push

I received this error message:

ERROR: Permission to user_a/myrepo.git denied to user_b.
fatal: Could not read from remote repository.

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

That was really strange, because the last time I used user_b was more than one year ago.

So, I dropped this issue and ChatGPT asked me to see the repository configuration:

git config --list

Nothing wrong here.

It also suggested me to verify if I had used HTTPS to clone the repository:

git remote -v

I was already using SSH.

So, it suggested me to confirm if which user the ssh was using to login to github.com:

$ ssh -T [email protected]
Hi user_b! You've successfully authenticated, but GitHub does not provide shell access.

Then it suggested me a very clever solution: create a separated ssh key with the name of my user and create a ssh config file and force git to use it:

ssh-add ~/.ssh/id_ed25519_user_a

And create the ~/.ssh/config with this content:

Host github-user-a
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_user_a
IdentitiesOnly yes

Then in my git repository I set to use this fake github-user-a host:

git remote set-url origin git@github-user-a:user_a/myrepo.git

That solution, although a little strange from my point of view, worked very well.