I'm trying to connect to a google cloud VM instance from a GitLab CI/CD runner to be able to deploy docker swarm stacks and services. However I find that when running

gcloud compute ssh <instance-name> --quiet 

from the google/cloud-sdk:alpine docker image the keys are uploaded to the image (as confirmed using the cloud console), however the connection fails with

ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].

When examining the output using -vvv, the last few lines of the output show

debug1: Offering RSA public key: /root/.ssh/google_compute_engine
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 60
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug2: input_userauth_pk_ok: fp SHA256:pbWpf3dF2nJgcR9Z7pPmIwTsS0IEKK5bgakYJfAQK5o
debug3: sign_and_send_pubkey: RSA SHA256:pbWpf3dF2nJgcR9Z7pPmIwTsS0IEKK5bgakYJfAQK5o
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).

Connecting using the SSH button in the cloud console works fine.

Any ideas as to what might be stopping this working?


After a bit of experimenting it turns out that signing in as a different user to root works, i.e. use

gcloud compute ssh <user-name>@<instance-name> --quiet 

and this works fine. I assume that google don't allow root ssh access to their instances.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.