当我根据用户提示使用 ssh 制作 git clone 时,它工作正常。
git clone ssh://URL.com/soft.git soft_git
ssh key id_rsa
和 id_rsa.pub
在 /home/user/.ssh
下
我的目的是用 sudo
执行 git 但我得到了以下错误
Cloning into '/home/user/git/soft'...
Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我创建了一个文件夹 /root/.ssh
并将 ssh key 复制到其中,但我遇到了同样的错误
如何正确使用sudo执行git
最佳答案
当您使用 sudo 运行 git 时,git 将以 root 身份运行。因为 git 以 root 身份运行,所以 ssh 以 root 身份运行。因为 ssh 以 root 身份运行,所以它试图以 root 身份登录到远程服务器。远程服务器对此不满意(本应如此!)
你需要做两件事:
将用户名放在您的 URL 中:ssh://myusername@URL.com/soft.git。
让 root 用户可以使用您的 SSH key ,因为它会在
/root/.ssh
而不是/home/user/.ssh
下查找。 (您也可以将 SSH 指向正确的 key ,但我不知道该怎么做,而且 SSH 对权限很挑剔。)
关于linux - 使用 sudo 制作 git clone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34917237/