gcloud计算复制文件实例目标



我在从实例复制文件,尤其是向实例复制文件时遇到问题。我在实例中创建了instance.txt(使用SSH),但这不起作用:

C:test>gcloud compute copy-files instance-4:~/instance.txt . --zone us-central1-b
Passphrase for key "censoredbyme":
unable to identify instance.txt: no such file or directory
ERROR: (gcloud.compute.copy-files) [C:Program FilesGoogleCloud SDKgoogle-cloud-sdkbin..binsdkscp.EXE] exited with return code [1].

编写完整路径有效:

C:test>gcloud compute copy-files instance-4:/home/stefan_pochmann_gmail_com/instance.txt . --zone us-central1-b
Passphrase for key "censoredbyme":
instance.txt              | 0 kB |   0.0 kB/s | ETA: 00:00:00 | 100%

为什么~/不起作用?文档示例使用它,它不应该是相同的吗?参见:

stefan_pochmann_gmail_com@instance-4:~$ cd ~/
stefan_pochmann_gmail_com@instance-4:~$ pwd
/home/stefan_pochmann_gmail_com

另一个方向根本不起作用(?):

C:test>gcloud compute copy-files local.txt instance-4:/home/stefan_pochmann_gmail_com --zone us-central1-b
Passphrase for key "censoredbyme":
scp: unable to open /home/stefan_pochmann_gmail_com/local.txt: permission denied
ERROR: (gcloud.compute.copy-files) [C:Program FilesGoogleCloud SDKgoogle-cloud-sdkbin..binsdkscp.EXE] exited with return code [1].
C:test>gcloud compute copy-files local.txt instance-4:/home/stefan_pochmann_gmail_com/ --zone us-central1-b
Passphrase for key "censoredbyme":
scp: unable to open /home/stefan_pochmann_gmail_com//local.txt: permission denied
ERROR: (gcloud.compute.copy-files) [C:Program FilesGoogleCloud SDKgoogle-cloud-sdkbin..binsdkscp.EXE] exited with return code [1].

为什么拒绝许可?好的,我试着~/而不是写完整的路径:

C:test>gcloud compute copy-files local.txt instance-4:~/ --zone us-central1-b
Passphrase for key "censoredbyme":
local.txt                 | 0 kB |   0.0 kB/s | ETA: 00:00:00 | 100%

它看起来像上传了文件,但文件不在那里。至少在/home/stefan_pochmann_mail_com/中没有。但我不知道,因为我必须使用~/,这在下载方向上根本不起作用。我该如何让它发挥作用?

Google Cloud SDK在本例中按预期工作。

当您第一次尝试使用gcloud compute命令时,它会告诉您"您没有Google计算引擎的SSH密钥",并且它通常会在C:Users<username>.ssh目录中创建私钥、公钥(.pub)和PuTTY-format密钥(.ppk)(不同的Windows版本可能会有所不同)。

如果打开google_compute_engine.pub文件,最后会找到用于访问实例的用户名。此用户名与您在执行gcloud命令时登录的本地用户名相匹配。

如果要运行gcloud compute copy-files instance-4:~/instance.txt . --zone us-central1-b,可以执行以下步骤:1-转到开发者控制台->选择您的项目->计算->计算引擎->元数据->SSH密钥->编辑和修改SSH密钥,Stefan出现在左边,键入stefan_pochmann_gmail_com,而不是Stefan在密钥内容的末尾。

好的,我刚刚解决了它。我的本地帐户是"Stefan",gcloud在实例中使用/home/Stefan作为~/(bug?)。这就解释了错误,上传的文件最终变成了/home/Stefan/local.txt(其中/home/STtefan和其中的所有内容都归新创建的用户"Stefan"所有。我不得不使用sudo删除它)。在实例名称之前添加"stefan_pochmann_gmail_com@"即可。

如果您想将文件从本地机器复制到谷歌云实例(gcloud)

然后使用以下命令:

gcloud compute scp [file location] [user]@[instance]:~/[location] --zone [zone name]

例如:

gcloud compute scp ~/Documents/hello.txt john@linux:~/MyFiles --zone us-east1-b

最新更新