Reputation: 11
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].
Upvotes: 0
Views: 824
Reputation: 11
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
Upvotes: 1