Unable to ssh to GCE: "Permission denied (publickey)"
After I was able to ssh via Google web console, I did the following steps to resolve this:
Generate ssh key using
Copy the key.pub file contents
Append the contents to
sudo nano ~/.ssh/authorized_keys
I faced the same situation because of the user. On google web shh my user name was showing something first part of my email. So, I was trying ssh like this
Later, I discover that, google creates a user based on the ssh key that you put on the google vm setting. So, first check the user at the end of the public key, and try following
When your instance is first created, it will not have any SSH keys in it by default, so you have to transfer them there, e.g., by using
gcloud to connect to it the first time as described in this SO answer or by manually creating SSH keys and manually adding them to your instance as described in another SO answer.
Make sure you don't have OS Login enabled. Docs read:
If you manage your SSH keys by using OS Login on instances, metadata-based SSH key configurations on those instances are disabled
Caution: Enabling OS Login on instances disables metadata-based SSH key configurations on those instances. Disabling OS Login restores SSH keys that you have configured in project or instance metadata.
To verify, go to project-level metadata (Compute Engine -> Metadata) and ensure that you have either no
enable-oslogin key or that it is set to
I had the same issue, and used gcloud command to login for the first time and added to
After I restarted the service:
systemctl restart sshd