使用 sudo 进行 git clone [英] make git clone with sudo

查看:116
本文介绍了使用 sudo 进行 git clone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我根据用户提示使用 ssh 进行 git clone 时,它​​可以正常工作.

when I make git clone with ssh from a user prompt it works properly.

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

ssh 密钥 id_rsaid_rsa.pub 位于 /home/user/.ssh

the ssh key id_rsa and id_rsa.pub are under /home/user/.ssh

我的目的是使用 sudo 执行 git,但出现以下错误

my purpose is the execute git with sudo but I got the following error

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 密钥复制到其中,但我遇到了同样的错误

I create a folder /root/.ssh and I copy the ssh keys into it but I got the same error

如何正确使用 sudo 执行 git.

how to execute git with sudo properly.

推荐答案

当您使用 sudo 运行 git 时,git 将以 root 身份运行.因为 git 以 root 身份运行,所以 ssh 以 root 身份运行.因为 ssh 以 root 身份运行,所以它试图以 root 身份登录到远程服务器.远程服务器对此不满意(应该如此!)

When you run git using sudo, git will run as root. Because git is running as root, ssh is running as root. Because ssh is running as root, it is trying to log on to the remote server as root. The remote server is not okay with this (as it should be!)

你需要做两件事:

  • 在您的 URL 中输入用户名:ssh://myusername@URL.com/soft.git.

  • Put the username in your URL: ssh://myusername@URL.com/soft.git.

让您的 SSH 密钥对 root 用户可用,因为它会在 /root/.ssh 下而不是 /home/user/.ssh 下查找.(您也可以将 SSH 指向正​​确的密钥,但我不知道该怎么做,而且 SSH 对权限很挑剔.)

Make your SSH key available to the root user, because it will look under /root/.ssh instead of /home/user/.ssh. (You could also probably point SSH at the correct key, but I don't know how to do this, and SSH is picky about permissions.)

这篇关于使用 sudo 进行 git clone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆