red888
red888

Reputation: 31520

how do I elevate my gcloud scp and ssh commands?

I want to be able to fire commands at my instance with gcloud because it handles auth for me. This works well but how do I run them with sudo/root access?

For example I can copy files to my accounts folder:

gcloud compute scp --recurse myinst:/home/me/zzz /test --zone us-east1-b

But I cant copy to /tmp:

gcloud compute scp --recurse /test myinst:/tmp --zone us-east1-b
pscp: unable to open directory /tmp/.pki: permission denied
19.32.38.265147.log       | 0 kB |   0.4 kB/s | ETA: 00:00:00 | 100%
pscp: unable to open /tmp/ks-script-uqygub: permission denied

What is the right way to run "gcloud compute scp" with sudo? Just to be clear, I of course can ssh into the instance and run sudo interactively

Edit: for now im just editing the permissions on the remote host

Upvotes: 2

Views: 563

Answers (1)

ingernet
ingernet

Reputation: 1524

Just so I'm understanding correctly, are you trying to copy FROM the remote /tmp folder, or TO it? This question sounds like you're trying to copy to it, but the code says you're trying to copy from it.

This has worked for me in the past for copying from my local drive to a remote drive, though I have some concern over running sudo remotely:

gcloud compute scp myfile.txt [gce_user]@myinst:~/myfile.txt --project=[project_name];
gcloud compute ssh [gce_user]@myinst --command 'sudo cp ~/myfile.txt /tmp/' --project=[project_name];

You would reverse the process (and obviously rewrite the direction and sequence of the commands) if you needed to remotely access the contents of /tmp and then copy them down to your local drive.

Hope this helps!

Upvotes: 3

Related Questions