1

When I try and push commits up to GitHub, I get a

Permission denied (publickey).
fatal: Could not read from remote repository.

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

Luckily, help.GitHub has a great article on solving SSH issues. I ran through this guide and found that ssh-add -l -E md5 returns The agent has no identities. The guide says to generate a new key, which I did. After that, ssh-add returns something like 2048 MD5:a0:dd:42:3c:5a:9d:e4:2a:21:52:4e:78:07:6e:c8:4d /Users/you/.ssh/id_rsa (RSA) as expected.

Great, I think, the problem's solved. I try another push, and get the same public key issue. I've made sure that my key is correctly set in GitHub. When I start a new session, ssh-add again returns no identities. I've even started the process from scratch following the article above. I've checked my permissions, and now I'm out of troubleshooting leads.

  • It's hard to know what happened without a full log of your actions, the values they returned, etc. For instance, if you started a new agent, you may have loaded your key into *that* agent, and not Apple's one -- which would explain a new terminal not knowing anything about it. – Charles Duffy Jun 04 '17 at 00:34
  • ...so, all the instructions to run `eval "$(ssh-agent -s)"` actually *aren't* appropriate on MacOS: Keychain already gives you an agent shared with everything in your session. – Charles Duffy Jun 04 '17 at 00:35
  • BTW, one you have a key in your agent ("your agent" being Apple Keychain, not anything you manually invoked), use `ssh-add -L` (yes, *capital* `L`) to dump the public side, and make sure it's exactly that you have in github -- just to be sure that it's the same key in both places. – Charles Duffy Jun 04 '17 at 00:36
  • https://apple.stackexchange.com/questions/48502/how-can-i-permanently-add-my-ssh-private-key-to-keychain-so-it-is-automatically is probably worth running through -- note the `UseKeychain` directive. – Charles Duffy Jun 04 '17 at 00:38
  • @CharlesDuffy Is there anything I can do to make this question more helpful? From my perspective, I was cruising along on a project, then one day I came back to it and no I can no longer push to GitHub, and I've no idea how to get back on track. – Ben Etherington Jun 04 '17 at 01:11
  • *shrug*. This would probably be neigh-trivial if I were actually present for an over-the-shoulder, but there are enough moving parts (or, rather, places where moving parts can *potentially* be configured in) and things that can *potentially* go wrong that it's a tricky one to describe full and complete troubleshooting steps in text. – Charles Duffy Jun 04 '17 at 01:55

1 Answers1

2

First, make sure your public key is correctly registered on your GitHub profile (as one continuous line, without any newline in it).

Second, make sure to generate (at least for testing) a private key not protected by a passphrase: you need ssh agent only to manage keys with passphrase. If your key has no passphrase, you don't need ssh agent at all.

  ssh-keygen -t rsa -C "key for GitHub access" -q -P ""

That will replace your current key, so make sure you don't need your current key anymore.
Test your key with ssh -T git@github.com

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Not using a passphrase was was the issue. I don't know why my key stopped working in the first place, but that got me up and running again! Thanks a bunch! Now I can work on figuring out why SSH-agent isn't behaving, and see if I can start using password protected keys again. – Ben Etherington Jun 04 '17 at 13:20
  • 1
    OS X behavior has changed. You need to re-add your keys after each login/restart. – Thorbjørn Ravn Andersen Jun 04 '17 at 14:31