我很困惑。我正在尝试获取 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.
不过,我觉得我已经完成了所有正确的步骤。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 key 进入我的 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
如果我尝试做sudo git clone --recursive git@github.com:shubham-goel/ucmr.git
我明白了fatal: Could not read from remote repository.
错误。此时可能是什么问题?如何诊断这个问题?谢谢你。
最佳答案
您看到问题是因为您使用的是 sudo
.
当您使用 SSH key 时,它来自用户的主目录,而当您使用 SSH 代理时,它来自环境。当您使用 sudo
,您更改了当前用户,因此 key 来自 root 的主目录,而 sudo
,默认情况下,出于安全原因清除环境。因此,无法访问您的 key ,您的操作将失败。
除非您有令人信服的理由,否则应避免使用 sudo
在这里,因为它不是必需的。如果您确定需要它并且您确定 PATH
中没有任何内容或其他可能存在安全风险的环境,您可以尝试使用 sudo -E
,这将避免清除环境,因此让您的 SSH 代理与您的克隆一起工作。
关于git - "You' 已成功验证,但 GitHub 不提供 shell 访问” 在运行完所有 ssh 设置步骤后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65524600/