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.