Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy files between two Google Cloud instances

I have two projects in Google Cloud and I need to copy files from an instance in one project to an instance in another project. I tried to using the 'gcloud compute copy-files' command but I'm getting this error:

gcloud compute copy-files test.tgz --project stack-complete-343 instance-IP:/home/ubuntu --zone us-central1-a 

ERROR: (gcloud.compute.copy-files) Could not fetch instance: - Insufficient Permission
like image 212
user1865445 Avatar asked Dec 01 '14 19:12

user1865445


People also ask

How do I transfer files from one GCP instance to another?

Transfer files using SSH-in-browserIn the Google Cloud console, go to the VM instances page. In the list of virtual machine instances, click SSH in the row of the instance that you want to connect to. After the connection is established, click the upload icon upload.

How do I copy instances to Google Cloud?

Click the name of the VM. The VM instance details page opens. In the toolbar at the top of the VM instance details page, click Create similar. The Google Cloud console copies the configuration and opens the Create an instance page.


2 Answers

I was able to replicate your issue with a brand new VM instance, getting the same error. Here are a few steps that I took to correct the problem:

Make sure you are authenticated and have rights to both projects with the same account!

$ gcloud config list (if you see the service account @developer.gserviceaccount.com, you need to switch to the account that is enabled on both projects. you can check that from the Devlopers Console > Permissions)

$ gcloud auth login (copy the link to a new window, login, copy the code and paste it back in the prompt)

$ gcloud compute scp test.tgz --project stack-complete-343 instance-IP:/home/ubuntu --zone us-central1-a (I would also use the instance name instead of the IP)

This last command should also generate your ssh keys. You should see something like this, but do not worry about entering a passphrase :

WARNING: [/usr/bin/ssh-keygen] will be executed to generate a key.

Generating public/private rsa key pair

Enter passphrase (empty for no passphrase):

like image 51
Marius I Avatar answered Sep 20 '22 21:09

Marius I


Go to the permissions tab on the remote instance(i.e. the instance you WON'T be running gcloud compute copy-files on). Then go to service accounts and create a new one, give it a name and check the box to get a key file for it and leave JSON selected. Upload that key file from your personal machine using gcloud compute copy-files and your personal account to the local instance(i.e. the machine you're SSHing into and running the gcloud compute copy-files command on.) Then run this from the local instance via SSH. gcloud auth activate-service-account ACCOUNT --key-file KEY-FILE replacing ACCOUNT with the email like address that was generated and KEY-FILE with the path to the key file you uploaded from your personal machine earlier. Then you should be able to access the instance that setup the account. These steps have to be repeated on every instance you want to copy files between. If these instructions weren't clear let me know and I'll try to help out.

like image 40
Scoopta Avatar answered Sep 19 '22 21:09

Scoopta