Solvedbrew Brew update fails with Permission denied (publickey).

Please follow the general troubleshooting steps first:

  • [DONE] Ran brew update and retried your prior step?
  • [DONE] Ran brew doctor, fixed as many issues as possible and retried your prior step? brew doctor is clean
  • [DONE] If you're seeing permission errors tried running sudo chown -R $(whoami) $(brew --prefix)?

Bug reports:

Doing brew update, I get the following

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

Please make sure you have the correct access rights
and the repository exists.
Error: Fetching /usr/local failed!
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Error: Fetching /usr/local/Library/Taps/homebrew/homebrew-boneyard failed!
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Error: Fetching /usr/local/Library/Taps/homebrew/homebrew-versions failed!
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Error: Fetching /usr/local/Library/Taps/dart-lang/homebrew-dart failed!
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Error: Fetching /usr/local/Library/Taps/homebrew/homebrew-dupes failed!
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Error: Fetching /usr/local/Library/Taps/homebrew/homebrew-x11 failed!
Already up-to-date.

Followed multiple hints on the web. This looks like an ssh related error but the reps in question point to https. Please advise. Did not do a brew update for a while and did the 10.11.4 upgrade in between. Still, I have been using some git. Maybe I have screwed something up. Please advise.

16 Answers

✔️Accepted Answer

@bm5k figured it out for 10.12, which uses ssh-agent now (cool). Just

ssh-add ~/.ssh/<your rsa file>

And then you can brew update

Other Answers:

FWIW I've had

[url "git@github.com:"]
    insteadOf = https://github.com/

In my ~/.gitconfig for ages and never had a problem until installing the 10.12 public beta.

There is some issue with your SSH setup. And you seem to be rewriting https://github.com/ remotes to git@github.com: as can be seen from the last output. Please check your ~/.gitconfig for a line similar to insteadOf = https://github.com/ that you must have added at some point in time (or some tool did for you) to your configuration. Please comment that out by prefixing the line with # and try again.

To maybe clarify a bit: I think if you look at your ~/.gitconfig you'll find a section that looks like this:

[url "git@github.com:"]
        insteadOf = https://github.com/

This has the effect of transparently rewriting all your GitHub HTTPS URLs to SSH. And this would explain why you see this behavior. This change to ~/.gitconfig was either made by you or by some Git-related tool you have installed since you've last successfully ran brew update. Do you remember doing something like this in the past 7 weeks (that's when your last updated Homebrew)?

More Issues: