0

Cannot copy files from Cloud Shell to virtual machine as super user.

The following code works for me, but I cannot use it to copy files to the protected directories within the LAMP stack (i.e. /opt/bitnami/apache2/htdocs).

gcloud compute scp --project "[MY PROJECT ID]" ~/file.php lampstack-vm:~/file.php

If I try to use: gcloud compute scp --project "[MY PROJECT ID]" ~/file.php lampstack-vm:~/opt/bitnami/apache2/htdocs/file.php I get the following error:

Permission denied (publickey). lost connection ERROR: (gcloud.compute.scp) [/usr/bin/scp] exited with return code [1].

  • Bitnami Engineer here. You also need to specify the user you are going to use when connecting to your remote instance. Can you try using `bitnami@lampstack-vm:~/file.php` when executing the command? There is a similar post [here](https://stackoverflow.com/questions/27807018/gcloud-compute-copy-files-permission-denied-when-copying-files) – Jota Martos Oct 21 '19 at 07:19
  • Thanks for your input. I found a solution. I had to give my username permission within the VM instance first with chown. And then, as you pointed out use my username@ for the copy into the instance. – Alfredo Cely Oct 21 '19 at 15:38

1 Answers1

1

Steps to copy files from Google Cloud Shell to VM

Step 1: Give your Google username permission in your VM machine directory with chown:

sudo chown -R [Your Google Cloud Username] [Directory for Permission]

Example: sudo chown -R myusername /opt/bitnami/apache2/htdocs

Step 2: Fun a gcloud compute scp command with the parameters below:

'''gcloud compute scp --project "PROJECT NAME" [Original Location in Cloud Shell] [Your Google Cloud Username]@[Name of VM Instance to receive file]:[Directory and file name]'''

Example: gcloud compute scp --project "myprojectname" ~/colors.php myusername@myvm-instance: /opt/bitnami/apache2/htdocs/colors.php

  • Hi Alfredo, giving write permissions to your username in the instance is one of the solutions but I don't suggest you to do that. It can break the application (this is not your case), that's why I suggested to use `bitnami@your-vm` because the `bitnami` user has write permissions in the installation. – Jota Martos Oct 22 '19 at 07:14
  • Ok got it Jota. I appreciate the follow up. Will change and use bitnami. – Alfredo Cely Oct 23 '19 at 09:17