I would like to run the following command:
ssh -A josh@remote_ip sudo git clone [email protected]: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.
gitwithsudo,sshis not looking in~josh/.sshfor the key any more; it's looking in~root/.ssh.sudoto move it to the correct location.sudoto run asec2-userinstead? You can create a dedicated key for that user and allow it to access the private repository using that key.ec2-userthere with no luck. Your initial comment about ssh looking in~root/.sshwas very helpful and allowed me to find what I think is the best solution for my problem