Search code examples
sshrsyncgoogle-compute-engine

rsync ssh file copying to GCE instance fails with permission denied


I'm executing the following on my local machine which is authenticated with my project in Google Compute Engine via the Google Cloud SDK:

rsync -avu --omit-dir-times -e ssh \
    -o UserKnownHostsFile=/dev/null \
    -o CheckHostIP=no -o StrictHostKeyChecking=no \
    -i /home/fredrik/.ssh/google_compute_engine \
    /somefolder/hello.txt \
    1.2.3.4:/mymount/

...where 1.2.3.4 is the public IP of my GCE instance and I get the following error:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.6]

The machine I execute the command on is authenticated and can, e.g., successfully execute gcloud compute ssh instance-1 in order to SSH into the same instance.

What do I need to do in order to successfully execute the rsync command?


Solution

  • Quotes around -e solved it:

    rsync -avu --omit-dir-times -e "ssh -o UserKnownHostsFile=/dev/null -o CheckHostIP=no -o StrictHostKeyChecking=no -i /home/fredrik/.ssh/google_compute_engine" /somefolder/hello.txt 1.2.3.4:/mymount/