Brew: Brew update fails with Permission denied (publickey).

Created on 8 Apr 2016  Â·  15Comments  Â·  Source: Homebrew/brew

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.

user configuration

Most helpful comment

@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

All 15 comments

This indeed looks like a problem specific to your configuration, but it's hard to judge what might be the issue from the information you provided thus far. Please post the output of brew config, brew doctor, and git -C /usr/local remote -v. Do you remember making any changes to your global or user's git configuration that might be related to this in the time between when it last worked and now?

@holgerfuessler Did you manage to solve your problem?

Apologees for the lag. It is not fixed.

➜ local git:(master) brew doctor
Your system is ready to brew.

➜ local git:(master) brew config
HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/Homebrew/homebrew
HEAD: dfaab6907b4057320e78edacab03e99f71904178
Last commit: 7 weeks ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_REPOSITORY: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com
CPU: quad-core 64-bit haswell
OS X: 10.11.4-x86_64
Xcode: 7.3
CLT: N/A
Clang: 7.3 build 703
X11: 2.7.8 => /opt/X11
System Ruby: 2.0.0-p648
Perl: /usr/bin/perl
Python: /usr/local/bin/python => /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Ruby: /usr/local/bin/ruby => /usr/local/Cellar/ruby/2.3.0/bin/ruby
Java: N/A

➜ local git:(master) git -C /usr/local remote -v
origin [email protected]:Homebrew/homebrew (fetch)
origin [email protected]:Homebrew/homebrew (push)

I did a system upgrade 10.11.4 which - following the release notes - might have affected openssh.

There is some issue with your SSH setup. And you seem to be rewriting https://github.com/ remotes to [email protected]: 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.

Just to make sure, can you post the output of brew tap-info --installed, to see if these are all https or ssh remotes?

If those tap remotes are [email protected]: links, then this may just happen: when you use ssh connections, and it wants to use your private key, git will pop up a dialog prompting for a passphrase the first time you use it. When git is run from inside brew, though, those dialogs don't happen and ssh key usage just fails (maybe because we're running git headless instead of attached to a tty). This happens to me sometimes, and you see error messages just like this.

If this is the case, you can work around it by manually switching in to one of the taps, or any other local GitHub clone using the same ssh identity, and do a git update. That'll produce the password prompt and store it for subsequent usage in your session, and brew update will be able to use it.

Or switch all the taps back to https remotes.

Confusing. All looks to be https:

➜ local git:(master) brew tap-info --installed
dart-lang/dart: unpinned, 1 formula
/usr/local/Library/Taps/dart-lang/homebrew-dart (521 files, 257.6K)
From: https://github.com/dart-lang/homebrew-dart

homebrew/boneyard: unpinned, 129 formulae, 8 commands
/usr/local/Library/Taps/homebrew/homebrew-boneyard (205 files, 365.6K)
From: https://github.com/Homebrew/homebrew-boneyard

homebrew/dupes: unpinned, 38 formulae
/usr/local/Library/Taps/homebrew/homebrew-dupes (229 files, 242.5K)
From: https://github.com/Homebrew/homebrew-dupes

homebrew/versions: unpinned, 265 formulae
/usr/local/Library/Taps/homebrew/homebrew-versions (707 files, 2.6M)
From: https://github.com/Homebrew/homebrew-versions

homebrew/x11: unpinned, 59 formulae
/usr/local/Library/Taps/homebrew/homebrew-x11 (498 files, 935.4K)
From: https://github.com/Homebrew/homebrew-x11
➜ local git:(master)

could you make an example for git update?

Cellar git:(master) git update
git: 'update' is not a git command. See 'git --help'.

Did you mean this?
update-ref

That looks right to me too, all https. And brew update only pulls from origin, so other remotes defined on them shouldn't matter. Does git fetch work okay if you cd to them and run it directly instead of through brew update?

Oh: by git update I meant git pull or git fetch. Sorry. I get mixed up because I use brew update so much.

Check your .git config file like Martin suggests. And once you've removed any rewriting, try doing brew update, and if that doesn't work, manually report origin for your main Homebrew repo to https://github.com/Homebrew/homebrew.git. A git remote set-url origin https://github.com/Homebrew/homebrew.git should accomplish that.

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

[url "[email protected]:"]
        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)?

Thank you guys.

commenting out
#[url "[email protected]:"]
# insteadOf = https://github.com/

fixed it. I have literally no idea how this config made it into .gitconfig . As for tools, I am using gitup sometimes but mostly pure vanilla command line git.

Again, appreciate your help. Brewing again.

FWIW I've had

[url "[email protected]:"]
    insteadOf = https://github.com/

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

@BM5k I'm seeing the same issue

@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

FYI, a lot of people have that line in their ~/.gitconfig because it is in the npm troubleshooting FAQ via this comment on npm/npm#5257.

This error can also occur the first time you interact with github when your '~/.ssh/known_hosts' file doesn't contain an entry for github.

A workaround is to do git pull or git clone in some other repo. You'll be asked to add the github ip to your known hosts. Say yes. brew should work afterward.

If you've upgrade to macOS Sierra there's a known issue (which seems deliberate on Apple's part) where it no longer reads your SSH passphrase from the Keychain, so every time you reboot you have to manually ssh-add -A if you fetch stuff from Git over SSH, otherwise you will see issues like that.

See https://github.com/jirsbek/SSH-keys-in-macOS-Sierra-keychain and the various sources linked to from there.

So the solutions should not be changing to https instead of ssh by modifying the .gitconfig in my opinion.

Was this page helpful?
0 / 5 - 0 ratings