2

One month ago I configured two github accounts on my mac: one account for work and another for personal use. I've been using both for a month without problems. In the day commiting/pushing/etc to repos from work. At night, commiting/pushing/etc in a couple of personal repos. Suddenly, today I was unable to push some changes in one of my personal account, the error is:

git push --set-upstream origin <branch>
ERROR: Permission to <repo>.git denied to <work-account>.
fatal: Could not read from remote repository.

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

I don't know why git push command is trying to push using my work account!?!?!?

My previous changes and push in this repo were 7 days ago with my personal account (without issues). I did not change anything in my config (ssh, .git/config files, etc.)!

I tried this in the directory of the repo:

git config user.email
git config user.name

Email is my personal email, so this is correct.

Why is git using my work account? Even if the git config command display my personal account? Also, this was working some days ago ...

Note 2:

  • I have both accounts defined in ~/.ssh directory: id_rsa, id_rsa.pub, id_rsa_, id_rsa_.pub.
  • ~/.ssh/config is also defined:
Host github.com
  Hostname github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

Host <githubpersonal>
  Hostname github.com
  User git
  IdentityFile ~/.ssh/id_rsa_<personal_account>
  • the remote origin of the repo I think it's well defined:
[remote "origin"]
    url = git@<githubpersonal>:<personal_account>/<repo>.git
    fetch = +refs/heads/*:refs/remotes/origin/*
  • if I run git remote -v I get:
origin  git@<githubpersonal>:<personal_account>/<repo>.git (fetch)
origin  git@<githubpersonal>:<personal_account>/<repo>.git (push)

I don't know why is not working anymore ...

M.G.
  • 369
  • 1
  • 14
  • 1
    `git config` will do nothing at all here; the `user.name` and `user.email` settings are only stored into new commits you make, and otherwise have nothing to do with your identity. Since you are using ssh, try `ssh -vT git@github.com` and `ssh -vT git@` and see which identity or identities you're sending. – torek Mar 13 '20 at 05:21
  • ok, I think there's something it's not right, this is the output: (1) ssh -vT git@github.com => "Hi ! You've successfully authenticated,...", which is right. But (2) ssh -vT git@ or ssh -vT , output is the same than previous "Hi ! You've successfully authenticated,..." Why work account in both? Is that right? (I think it's not) – M.G. Mar 13 '20 at 13:35
  • It just reboot and it's weird. Try to push and no error!. Ran ssh -vT and the greeting is using the personal account ... – M.G. Mar 13 '20 at 14:29
  • The `UseKeychain yes` suggests you're on a Mac. When you log in on the Mac you establish some keys (run `ssh-add -l` to see them) and your ssh will offer those keys to the other system; apparently those are the ones that GitHub is using to identify you. Consider setting the `IdentitiesOnly` settings here, so that you can direct your ssh to withhold some keys and only offer the ones you list in your `.ssh/config`. – torek Mar 13 '20 at 17:05

1 Answers1

0

Check your config file for any pushURL configuration, to check if it tries and push using an URL you do not expect.

Note: the SSH URL you can test is githubpersonal, not git@githubpersonal, since git is already specified in ~/.ssh/config

ssh -Tv githubpersonal
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I'm not sure if I know how to check that ... What I've done was use command `git remote -v` and it seems to be fine. Also I've check the config file in the proyect and it also seems to be fine (you can see the output in the notes 2). Is that what I have to check or is it something else? – M.G. Mar 13 '20 at 13:46
  • @M.G. just (in the repo folder) `git config -l` – VonC Mar 13 '20 at 14:22
  • ah ok, I just execute it and I can see two entries "user.email": first one for my work email, and then some lines below another entry for my personal email. Also the entry "remote.origin.url" seems to be right "git@:...". Should I delete the "user.email" entry with my work email? How can I do that? – M.G. Mar 13 '20 at 14:28
  • @M.G. No, one is overridden by the other: you can see which is which with `git config -l --show-origin` (and, next week, with git 2.26 which is about to be released: `git config -l --show-origin --show-scope`: https://stackoverflow.com/a/60286340/6309) – VonC Mar 13 '20 at 15:59