linux - 使用 sudo 制作 git clone

标签 linux git ssh sudo

当我根据用户提示使用 ssh 制作 git clone 时,它​​工作正常。

git clone ssh://URL.com/soft.git soft_git

ssh key id_rsaid_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/

相关文章:

ruby - 当 shell 有子进程时,为什么 ruby​​ 的 PTY 库无法捕获输入?

c++ - #include<boost> 没有这样的文件或目录

git - 我可以同时在 SVN 和 GIT 存储库上共享同一个 eclipse 项目吗?

ssh - 在 MobaXTerm 中更改 Vim 光标

eclipse - Eclipse Git(EGit)远程:无效的数据包行 header

linux - 如何使用ssh接口(interface)请求NASMT Q700 QNAP linux硬盘智能状态?

Python 结构在 Linux 下不工作。编码?

php - 我可以在升级前在 Linux 服务器上获得以前的 PHP 版本吗?

ruby-on-rails - 通过 capistrano 将特定的 git 分支部署到临时服务器

git - 如何拒绝/将自己从(协作)GitHub 存储库中删除?