Gcloud: Copy files between two VM instances

gcloudgoogle-compute-engine

I have two Google Compute Engine instances: instance-1 and instance-2, and I want to copy files from instance-1 to instance-2. Both instances are in the same project and zone.

In instance-1, I ran:

gcloud compute copy-files *.tar.bz2 instance-2:/mnt/pd1/home/ --zone  us-central1-b

and got this error message:

ERROR: (gcloud.compute.copy-files) Could not fetch instance:
- Insufficient Permission

Running gcloud config list on both instances shows that they use the same service account:

Your active configuration is: [NONE]
[core]
account = 00000000XXXXX-compute@developer.gserviceaccount.com
disable_usage_reporting = True
project = abc-123

Is there a simple way to copy files between two VM instances without switching accounts (i.e., gcloud auth login)?

Best Answer

You can set the service account scopes for Google Cloud APIs when creating your GCE instance. By doing so your service account on this GCE instance will have the authorization to make API calls on your behalf. You can refer to this link for more information.