You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用sudo执行git clone时出现Permission denied (publickey)错误的排查求助

使用sudo执行git clone时出现Permission denied (publickey)错误的排查求助

我昨天把笔记本系统从Jammy升级到了Noble,正在重新配置GitHub的SSH密钥。我生成了新的SSH密钥,用ssh-add添加了它,并且完成了所有官方要求的配置步骤。

目前普通用户身份下,SSH验证是正常的:

$ ssh -T git@github.com
Hi MokshC! You've successfully authenticated, but GitHub does not provide shell access.

用ssh-add -l -E md5查看已加载的密钥,结果也符合预期。但当我用sudo执行克隆命令时,却碰到了公钥权限拒绝的错误:

$ sudo git clone git@github.com:MokshC/repo.git
Cloning into 'repo'...
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.

有没有大佬能给点排查思路或者解决建议?

补充:如果不用sudo执行的话,会出现另一个错误:fatal: could not create work tree dir 'repo': Permission denied

备注:内容来源于stack exchange,提问作者Moksh Chitkara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 09:30:27