3

我无法从实例复制文件,尤其是复制到实例。我在实例中创建了 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 Files\Google\Cloud SDK\google-cloud-sdk\bin\..\bin\sdk\scp.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 Files\Google\Cloud SDK\google-cloud-sdk\bin\..\bin\sdk\scp.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 Files\Google\Cloud SDK\google-cloud-sdk\bin\..\bin\sdk\scp.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_gmail_com/ 中。但我不知道,因为我不得不使用 ~/ 这在下载方向上根本不起作用。我怎样才能让它工作?

4

3 回答 3

5

在这种情况下,Google Cloud SDK 按预期工作。

当您第一次尝试使用gcloud compute命令时,它会告诉您“<em>您没有用于 Google Compute Engine 的 SSH 密钥”,它会创建私钥、公钥 (.pub) 和 PuTTY 格式的密钥 ( .ppk)通常在C:\Users\<username>\.ssh\目录中(不同的 Windows 版本可能不同)。

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

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

于 2014-11-18T15:29:10.747 回答
4

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

于 2014-11-06T09:26:32.583 回答
2

如果您想将文件从本地机器复制到谷歌云实例(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

于 2017-11-22T19:20:09.090 回答