简体   繁体   中英

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 . The command doesn't work if I include sudo into a directory I already own.

Since I need to use sudo to write into the other user's directory, how can I get this command to work? Logging in as ec2-user is not a possible solution.

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.

To fix this, I used visudo to add this line to my /etc/sudoers file:

Defaults    env_keep += "SSH_AUTH_SOCK"

Source

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM