我很困惑。我试图让该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 代理正常工作和你的克隆人。
小智 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。
归档时间: |
|
查看次数: |
24797 次 |
最近记录: |