[英]Clone private git repo to remote host using sudo
I would like to run the following command:我想运行以下命令:
ssh -A josh@remote_ip sudo git clone git@github.com:private/private-repo.git /home/ec2-user/private-repo
but I get an error:但我收到一个错误:
Cloning into '/home/ec2-user/private-repo'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
The command works when I want to clone into a directory I own ( ~/private-repo
) without sudo
.当我想在没有
sudo
的情况下克隆到我拥有的目录 ( ~/private-repo
) 时,该命令有效。 The command doesn't work if I include sudo
into a directory I already own.如果我将
sudo
包含到我已经拥有的目录中,该命令将不起作用。
Since I need to use sudo
to write into the other user's directory, how can I get this command to work?由于我需要使用
sudo
写入其他用户的目录,我怎样才能让这个命令工作? Logging in as ec2-user
is not a possible solution.以
ec2-user
身份登录不是可行的解决方案。
Thank you to @chepner for pointing me in the direction of the issue: my ssh key does not get passed to ~root/.ssh
when I use sudo.感谢@chepner 为我指出问题的方向:当我使用 sudo 时,我的 ssh 密钥没有传递给
~root/.ssh
。
To fix this, I used visudo
to add this line to my /etc/sudoers
file:为了解决这个问题,我使用
visudo
将此行添加到我的/etc/sudoers
文件中:
Defaults env_keep += "SSH_AUTH_SOCK"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.