Reputation: 21
I am new to google cloud. I have seen the similar question but I couldn't understand the answer. It will be great if someone could give easy instruction to tackle this problem. I have two linux VM instances under same project on google cloud. I want to copy files from one VM to other VM.
I tried copy-files command. It threw error "deprecated, use scp instead" I tried "gcloud compute scp user@vm2_instance_name:vm2_instance_file_path"
other answers say use "service account". I read about them and created one and created key as well in .json format but not sure what to do after that. Appreciate any suggestions.
Upvotes: 0
Views: 676
Reputation: 8074
This is the solution that worked for me:
1. gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE
INTERNAL_IP EXTERNAL_IP STATUS
instance-1 us-central1-a n2-standard-8
10.128.0.60 34.66.177.187 RUNNING
instance-2 us-central1-a n1-standard-1
10.128.15.192 34.69.216.153 STAGING
2. gcloud compute ssh instance-1 --zone=us-central1-a
3. user@instance-1:~$ ls
myfile
4. usernstance-1:~$ gcloud compute scp myfile user@instance-2:myfile
5. gcloud compute ssh instance-2 --zone=us-central1-a
6. user@instance-2:~$ ls
myfile
Upvotes: 0
Reputation: 76018
If you are in one instance, don't worry about Google Cloud. Simply perform a scp
to copy file from VM to another one.
If you don't have customize users on the VM, you can omit it
scp <my local file path> <vm name>:<destination path>
About service account, if your VM are in Google Cloud, they have the compute engine service account by default <projectNumber>[email protected]
You can customize this service account if you want. This service account is mandatory to identify the VM which perform API call or gcloud
command
Upvotes: 1
Reputation: 1310
Google's documentation addresses this. Personally, I have always preferred using gcloud compute scp
as it provides both a simplistic way of performing transfers while not necessarily taking away any of the complexities and features that other transferring options provide.
In any case, in the documentation provided you will most likely find the method that are more in-line with what you want.
Upvotes: 0