git@github.com: Permission denied (publickey) when doing a brew cask install "program"

Viewed 2112

Whenever I try to do a git clone, or a brew install I get the following error:

Not sure what the issue is and I am using ohmysh

==> Tapping homebrew/cask
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Error: Failure while executing; `git clone https://github.com/Homebrew/homebrew-cask /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask` exited with 128.
Follow the instructions here:
  https://github.com/Homebrew/homebrew-cask#reporting-bugs
/usr/local/Homebrew/Library/Homebrew/utils.rb:266:in `safe_system'
/usr/local/Homebrew/Library/Homebrew/tap.rb:273:in `install'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:157:in `run'
/usr/local/Homebrew/Library/Homebrew/cask/cmd.rb:123:in `run'
/usr/local/Homebrew/Library/Homebrew/cmd/cask.rb:9:in `cask'
/usr/local/Homebrew/Library/Homebrew/brew.rb:103:in `<main>'
2 Answers

Answer was in my .gitconfig file.

Had to comment out this line:

#   insteadOf = https://github.com/```

The solution provided by OP is certainly a valid workaround, but for more context, the full piece of Git configuration that caused this behavior likely looked something like this:

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

This has the effect of forcing any GitHub requests made over HTTPS to instead use SSH. The git@github.com: Permission denied (publickey) notice indicates that you are not set up to use SSH via GitHub.

For some additional background/discussion:

The GitHub docs on Authenticating with GitHub from Git recommend connecting over HTTPS, so if you're fine with that, you can remove the original lines of configuration.

If you would prefer to always connect over SSH, you can keep the configuration as is, and follow the instructions on Connecting to GitHub with SSH.

Related