I'm trying to copy a file into a compute instance using gcloud
like this:
gcloud compute scp ./file.txt.bz2 root@instance-1:/home/mehran/
And I'm facing an error:
No zone specified. Using zone [us-central1-c] for instance: [instance-1].
root@###.###.###.###: Permission denied (publickey).
lost connection
ERROR: (gcloud.compute.scp) [/usr/bin/scp] exited with return code [1].
I've also tested without root:
gcloud compute scp ./file.txt.bz2 instance-1:/home/mehran/
And facing the same error. This is in the case that I can ssh
into the same instance without any issue:
gcloud compute ssh instance-1
Apparently, my user does not have the write permission to the home folder! Even a chmod 777
did not help. I ended up copying to /tmp
folder and then pick it up from there!
For some reason, the ssh (web-based) and scp were using different users. That's why my scp user didn't have access to that folder. It was trying to write into another user's home folder.