`gcloud compute copy-files`:复制文件时权限被拒绝

bry*_*yan 22 linux permissions ubuntu google-compute-engine gcloud

我很难将文件复制到我的Google Compute Engine.我在Google Compute Engine上使用Ubuntu服务器.

我是从我的OS X终端这样做的,我已经被授权使用了gcloud.

local:$ gcloud compute copy-files /Users/Bryan/Documents/Websites/gce/index.php example-instance:/var/www/html --zone us-central1-a
Warning: Permanently added '<IP>' (RSA) to the list of known hosts.
scp: /var/www/html/index.php: Permission denied
ERROR: (gcloud.compute.copy-files) [/usr/bin/scp] exited with return code [1].
Run Code Online (Sandbox Code Playgroud)

Mai*_*puu 65

root@在实例名称之前插入:

local:$ gcloud compute copy-files /Users/Bryan/Documents/Websites/gce/index.php root@example-instance:/var/www/html --zone us-central1-a
Run Code Online (Sandbox Code Playgroud)

  • 啊,还有一些证据.我不能以root身份`ssh`进入VM实例.或许最好将这些文件"scp"到像`/ tmp`这样的中间位置,而不是尝试启用它. (4认同)

Mis*_*man 18

这不起作用的原因是您的用户名没有GCE VM实例的权限,因此无法写入/var/www/html/.

请注意,由于此问题与Google Compute Engine虚拟机有关,因此您无法直接SSH到虚拟机root,也无法直接复制文件root,原因相同:依赖于身份验证的gcloud compute copy-files用途.scpssh

可能的解决方案:

  1. (Faizan在评论中也建议)这个解决方案每次都需要两个步骤

    1. 用于gcloud compute copy-files传输用户可以写入的文件/目录,例如,/tmp/home/$USER

    2. 通过gcloud compute ssh或通过控制台上的SSH按钮登录GCE VM 并使用复制sudo来获取适当的权限:

      # note: sample command; adjust paths appropriately

      sudo cp -r $HOME/html/* /var/www/html

  2. 这个解决方案是一些事先准备工作的一步:

    1. 一次性设置:/var/www/html直接给你的用户名写入权限; 这可以通过几种方式完成; 这是一种方法:

      # make the HTML directory owned by current user, recursively

      sudo chown -R $USER /var/www/html

    2. 现在您可以一步运行副本:

      gcloud compute copy-files /Users/Bryan/Documents/Websites/gce/index.php example-instance:/var/www/html --zone us-central1-a