How to Resolve GCP Public Key SSH Error?

A user encountered a “public key” error while trying to access a virtual machine (VM) on the Google Cloud Platform. In this article, we will look at the steps that can be taken to resolve such an issue.

  1. Check Putty Version: First and foremost, it’s important to check the version of Putty being used. Older versions may encounter such errors. Using the latest version of Putty can often resolve the issue. You can look for relevent information

2. Edit sshd_config: Access the sshd_config file, which is the configuration file required for SSH access. SSH into the VM and open the file located at /etc/ssh/sshd_config. Update the following two lines:

PasswordAuthentication yes 
ChallengeResponseAuthentication yes
  • PasswordAuthentication yes: This setting allows SSH users to access the server using password authentication.
  • ChallengeResponseAuthentication yes: This setting allows the SSH server to authenticate users using additional challenge-response methods.

3. Restart SSH Service: Restart the SSH service for the changes to take effect. You can use the following command in the terminal:

sudo /etc/init.d/ssh restart

OS Login Settings

In some cases, changes made in the VM settings through the Google Cloud Console can also resolve the issue. For example, navigating to the desired project in GCloud, selecting Compute Engine, then Metadata from the left menu, and changing the ‘enable-oslogin’ setting from ‘True’ to ‘False’ in the main Metadata pane can resolve the issue.

After following these steps, the “public key” error in SSH access is usually resolved, and users can successfully access the VM via SSH.

--

--