Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Issue with Adding SSH Keys

Hey everyone,
I’m trying to automate the creation of VMs on Google Cloud and followed the steps to add SSH keys. The issue is, even though the key looks like it’s been added correctly (both through the GUI and console), the user doesn’t get created. If I manually create the user on the VM and add the public key, SSH works just fine. Could this be an issue with missing permissions or am I missing something else? Has anyone run into this problem and have any tips on how to fix it?

Thanks a lot!

1 3 437
3 REPLIES 3

Hi @rafoleto ,

Welcome to Google Cloud Community!

While adding the key are you defining the username as stated in this documentation?

Hi @rafoleto,  

Welcome to Google Cloud Community!

It seems there was a permission issue preventing the automated VM creation process from adding your SSH key.  When you add SSH keys to your Google Account, Compute Engine generates a username using your email. Make sure the service account that created the VM has the required permissions. You can check the Compute OS Login External User role for the permissions needed to add an SSH key.

For more reference in Adding SSH keys to VMs please refer to following links:

I hope the above information is helpful.

Got it, the issue is with OS Login. If I disable it, I can use this to add users and SSH keys when creating a VM:
resource "google_compute_project_metadata" "default" {
metadata = {
ssh-keys = <<EOF
dev:ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILg6UtHDNyMNAh0GjaytsJdrUxjtLy3APXqZfNZhvCeT dev
test:ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILg6UtHDNyMNAh0GjaytsJdrUxjtLy3APXqZfNZhvCeT test
EOF
}
}
But is there a way to keep OS Login enabled and still make this script work?