'How to connect to GCP VM instance with password using SSH?

I able to connect to my VM instance in GCP with a SSH key. I added user with the sudo useradd -m -s /bin/bash -G {groups} {new user name} command, and changed the password with th passwd {new user name} command.

I tried to connect to the VM instance with SSH but i received this error: Permission denied (publickey).

Please help me.



Solution 1:[1]

By default, SSH login using a password (as opposed to keys) is disabled on newly created Linux Compute Engines. Fortunately, it can be enabled pretty quickly.

Login to the Linux environment and then edit the text file found at:

/etc/ssh/sshd_config

Look for the line which reads:

PasswordAuthentication no

and change it to

PasswordAuthentication yes

Save the file.

Finally, restart SSH using:

  1. If your OS is Ubuntu/Debian:
sudo service ssh restart
  1. If your OS is CentOS/RedHat:
sudo service sshd restart

At this point, you will now be able to login using SSH using a userid/password pair.
To set the password for $USER, do:

sudo passwd $USER

References:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 eric.itzhak