Failed to ssh to a deployed VM with correct username/password

Problem

When you fail to ssh to a deployed VM with correct username/password, the returned message may look like:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic)

Explanation

It's likely that the ssh request is denied because password authentication in virtual machine's sshd daemonis disabled.

Resolution

RHEL7.x, RHEL8.x, RHEL9.x

In the /etc/cloud/cloud.cfg file of the source image, the ssh_pwauth config key determines whether or not sshd will be configured to accept password authentication. Setting ssh_pwauth to 1 will enable password auth, which means that PasswordAuthentication config key in /etc/ssh/sshd_config will be set to yes. Setting to 0 will disable password auth, the PasswordAuthentication config key will be set to no. And the literal string unchanged will leave sshd unchanged.

Configure the /etc/cloud/cloud.cfg file when you create an image. See "Install and configure cloud-init"

RHCOS4

The igition file you upload before deploying contains ssh configuration in users config key. You can add users which can ssh to a deployed VM as follows:

{
  "ignition": { "version": "3.1.0" },
  "passwd": {
    "users": [
      {
        "name": "systemUser",
        "passwordHash": "$superSecretPasswordHash.",
        "sshAuthorizedKeys": [
          "ssh-rsa veryLongRSAPublicKey"
        ]
      }
  }
}

Either "passwordHash" or "sshAuthorizedKeys" is optional, you can use users name and password to ssh vm or use ssh authorized key without password.

To add more users, configure them within the users list structure ([...]).