在GCP CE中将文件从一个VM传输到另一个VM [英] Transfer files from one VM to another in GCP CE

查看:76
本文介绍了在GCP CE中将文件从一个VM传输到另一个VM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用scp方法将文件从一个VM实例移动到另一个VM实例.但是我已经知道,不可能从源实例直接进行传输.例如scp db.sql user @ instance-src:/home/data/db.sql

I am trying to move a file from one VM instance to another using scp method. However I had understood that it is not possible to do the direct transfer from the source instance. e.g scp db.sql user@instance-src:/home/data/db.sql

我尝试使用gcloud scp命令,但这仅允许我进行从本地到远程的传输.这意味着我需要先从源文件下载文件到本地.

I tried using the gcloud scp command but this allows me to do a transfer from local to remote only. This means I need to first download the file from the source to local.

是否有更好的方法来完成此任务?

Is there a better way to do this task?

推荐答案

首先,您需要使用命令 ssh-keygen 在source-vm上创建公共密钥,然后您可以使用以下命令查看公共密钥命令 cat .ssh/id_rsa.pub .现在,将源VM实例的公钥添加到目标vm实例的/home/user-name/.ssh/authorized_keys中.现在,您可以按照@Johnhanley所说的那样将文件从源vm传输到目标vm.

First you need to create public key on the source-vm using the command ssh-keygen then you can see the public key using the command cat .ssh/id_rsa.pub. Now add the public key of source VM instance to the /home/user-name/.ssh/authorized_keys of destination vm instance. Now, you can transfer the files from the source-vm to the destination-vm as @Johnhanley said.

或者,使用以下命令,您可以使用以下gcloud命令将文件从一个VM传输到另一个VM:

Alternatively, using the below command you can transfer the file from one VM to another VM using below gcloud command:

gcloud compute ssh source-vm --command='scp db.sql user@destination-vm:/home/file-transfer-location --zone=us-central1-a'

这篇关于在GCP CE中将文件从一个VM传输到另一个VM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆