`gh cli` 失败 `git@github.com: Permission denied (publickey)` 但 `gh desktop` 没问题

`gh cli` fails `git@github.com: Permission denied (publickey)` but no problem with `gh desktop`

我有点不好意思承认,到目前为止我用过[​​=17=]
我现在决定尝试使用 gh cli 我按照 documentation

安装
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-key C99B11DEB97541F0
sudo apt-add-repository https://cli.github.com/packages
sudo apt update
sudo apt install gh

明显成功

$ which gh
/usr/bin/gh
$ gh --version
gh version 1.8.1 (2021-04-02)
https://github.com/cli/cli/releases/tag/v1.8.1

但要克隆一个 public 存储库(例如 flutter gallery)运行 gh repo clone flutter/gallery
我收到以下错误

Cloning into 'gallery'...
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.
exit status 128

gh-desktop 的“开箱即用”一切都有效)
我错过了什么?

github discussion

如果你直接使用ssh有同样的问题,请先检查:

ssh -T git@github.com

如果是这种情况,请检查您的 ~/.ssh 内容,并确保您有 added and then tested 一个 SSH 密钥,以便该密钥可以从命令行运行(因为 GitHub桌面可能会在内部管理自己的 GitHub 桌面应用程序密钥)

因为即使克隆 public 存储库也需要身份验证
运行 gh auth login 修复了问题
我已经打开 issue 提议 clearer authentication error message