Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google cloud scp permission denied

I am trying to transfer files to my Google cloud hosted Linux (Debian) instance via secure copy (scp). I did exactly what the documentation told to connect from a local machine to the instance. https://cloud.google.com/compute/docs/instances/connecting-to-instance.

  • Created a SSH keygen
  • Added the keygen to my instance

I can login successfully by:

ssh -i ~/.ssh/my-keygen [USERNAME]@[IP]

But when I want to copy files to the instance I get a message "permission denied".

scp -r -i ~/.ssh/my-keygen /path/to/directory/ [USERNAME]@[IP]:/var/www/html/

Permission denied

It looks like the user with which I login has no permissions to write files, so I already tried to change the file permissions of /var/www/, but this still gives the permission denied message.

I also tried to add the user to the root group, but this still gives the same problem.

usermod -G root myuser
like image 547
Robbert Avatar asked Nov 15 '25 02:11

Robbert


1 Answers

The command line should be

scp -r -i ~/.ssh/my-keygen /path/to/directory/ [USERNAME]@[IP]:/var/www/html/

Assuming your files are in the local /path/to/directory/ and the /var/www/html/ is on the remote server.

The permissions does not allow to write in the /var/www/html/. Writing to /tmp/ should work. Then you can copy the files with sudo to the desired destination with root privileges.

like image 169
Jakuje Avatar answered Nov 17 '25 19:11

Jakuje



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!