我想运行以下命令:
ssh -A josh@remote_ip sudo git clone git@github.com:private/private-repo.git /home/ec2-user/private-repo
但是我得到一个错误:
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.
当我想克隆到一个没有sudo
的目录(~/private-repo
(中时,该命令会起作用。如果我将sudo
包含到我已经拥有的目录中,则该命令不起作用。
既然我需要使用sudo
写入其他用户的目录,我该如何让这个命令工作?以ec2-user
身份登录不是一个可行的解决方案。
感谢@chepner为我指明了问题的方向:当我使用sudo时,我的ssh密钥不会传递给~root/.ssh
。
为了解决这个问题,我使用visudo
将这一行添加到我的/etc/sudoers
文件中:
Defaults env_keep += "SSH_AUTH_SOCK"
源