I am trying to copy local files to /var/www/
.
The instance has two sets of keys. One for the instance creator that's generated by default and one for remote access that I have set up manually.
I have successfully logged in via gcloud
as the latter user, and I can change to root once I'm logged in. But when I try to log in with root privileges via root@instance-name
or instance-creator-name@instance-name
, I get Permission denied (publickey)
.
Do I need to generate a new key pair for the instance creator? Can the instance creator's private key be found somewhere (wouldn't that violate security)? Is there another way to log in as root?
Edit: The docs leaves that part unspecified.
The following example demonstrates copying a folder called css into the >default document directory and doing so as the root user because that user owns the /var/www remote directory:
$ gcloud compute copy-files ~/mysite/css root@<YOUR-INSTANCE>:/var/www
This should work according to the docs, but I get Permission denied
instead. Thinking I might have messed up my SSH configuration, I forced gcloud to use the default private key and then my manually generated key, but neither worked.
gcloud compute instances create --zone=us-central1-f ssh-root-test && gcloud compute copy-files --zone=us-central1-f /tmp/foo root@ssh-root-test:/var/
works. Which image are you using? Has it been modified?gcloud compute ssh
just uses regular SSH along with some Compute Engine-specific bits to get the key onto the instance–you can debug by checking e.g. the SSH daemon settings on the server,/etc/root/.ssh/authorized_keys
, etc.gcloud
handles sync-ing the key. If you'd really like to do this with your initial instance, you'll have to dig a little bit into its SSH settings. It works no differently from any other *nix host, except that the.authorized_keys
files are automatically populated. In any event, glad you've gotten it working.