Search code examples
google-cloud-platformsshgoogle-compute-enginemetadata

The following key(s) are missing the <username> at the front when adding to GCP VM metadata


I am trying to add a public ssh key in an GCP VM instance metadata.

gcloud compute instances add-metadata <instance-name> --zone=us-east4-a  --metadata-from-file ssh-keys=id_rsa.pub

The key has the format

ssh-rsa AAAAB3NzaC1yc2 ...
....root@hostname

Why am I getting this warning

WARNING: The following key(s) are missing the <username> at the front
ssh-rsa AAAAB3NzaC1yc2 ...
....root@hostname

What is more, after adding the public key to the node's metadata and although I am inside the GKE cluster and I have connectivity to the private IP of the node the ssh process fails

ssh <private_ip_of_the_node>
root@<private_ip_of_the_node> Permission denied (publickey).

Solution

  • By default, Compute Engine VMs built from public images and most common operating systems don't allow root login with a password over SSH. Here, you are using the GKE cluster Private IP [root@<private_ip_of_the_node>] which may not have the root permissions and this might give you Permission denied (publickey).