完成所有 ssh 设置步骤后,“您已成功通过身份验证,但 GitHub 不提供 shell 访问权限”

nig*_*row 9 git ssh ubuntu

我很困惑。我试图让该git clone命令正常工作,但它一直说:

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.
Run Code Online (Sandbox Code Playgroud)

不过,我觉得我已经完成了所有正确的步骤。

1-我已经安装了git。当我这样做时,git --version它说git version 2.17.1

2-我也完成ssh-keygen -t ed25519 -C "my_email@example.com"并查看了id_ed25519.pub我的.ssh文件夹中的文件。

3-我已经完成eval "$(ssh-agent -s)"并将ssh-add ~/.ssh/id_ed25519内容id_ed25519.pub作为 SSH 密钥复制到我的 Github 中。

然后当我这样做时

ssh -T git@github.com

我得到:

The authenticity of host 'github.com (140.82.114.4)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,140.82.114.4' (RSA) to the list of known hosts.
Hi nightfarrow! You've successfully authenticated, but GitHub does not provide shell access.
Please make sure you have the correct access rights
Run Code Online (Sandbox Code Playgroud)

如果我尝试做

sudo git clone --recursive git@github.com:shubham-goel/ucmr.git

我得到了那个fatal: Could not read from remote repository.错误。

此时可能出现什么问题?如何诊断这个问题?谢谢。

bk2*_*204 14

您遇到问题是因为您正在使用sudo.

当您使用 SSH 密钥时,该密钥来自用户的主目录;当您使用 SSH 代理时,该密钥来自环境。当您使用 时sudo,您会更改当前用户,因此密钥来自 root 的主目录,并且sudo出于安全原因,默认情况下会清除环境。因此,无法访问您的密钥,并且您的操作会失败。

除非你有令人信服的理由,否则你应该避免sudo在这里,因为它不是必需的。如果您确定需要它,并且确定您PATH或环境的其他部分中没有任何内容可能存在安全风险,您可以尝试使用sudo -E,这将避免清除环境,从而让您的 SSH 代理正常工作和你的克隆人。

  • 不过,当我尝试不使用“sudo”时,“权限被拒绝”...但是“sudo -E”有效!我想知道那里发生了什么事。谢谢。 (2认同)

小智 9

我也遇到了这个问题并解决了如下..

为我解决这个问题的唯一代码是通过复制我的存储库的 ssh url 类型来在本地计算机上设置远程 url;目前在 github 上他们是三个;Github CLI、Https 和 SSH,在他们停止使用密码身份验证之前,我最初使用的是 Https url;https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/。因此,在到达这一点之后,我遇到了这个错误,下面的代码修复了它。

git remote set-url origin git@github.com:username/your-repository.git

替换git@github.com:username/your-repository.git为 git hub 中的 ssh URL。