SSH password authentication is allowed on an Azure Linux VM

Use key authentication for SSH access to Azure Linux VMs.

Description

When creating an Azure Linux VM, supply the administrator’s SSH public key in osProfile.linuxConfiguration.ssh.publicKeys and set disablePasswordAuthentication to true.

Potential impact

With false, anyone who can reach SSH can attempt to log in with an administrator password.

Remediation

On an existing VM, open a separate SSH session with the administrator’s key before disabling password logins in the guest. Restrict management access and keep the private key on the client.

Examples

Place the excerpt inside the VM’s osProfile. Supply the administrator account as adminUsername and its SSH public key contents as adminPublicKey.

Before

bicep
linuxConfiguration: {
  disablePasswordAuthentication: false
}

After

bicep
linuxConfiguration: {
  disablePasswordAuthentication: true
  ssh: {
    publicKeys: [
      {
        path: '/home/${adminUsername}/.ssh/authorized_keys'
        keyData: adminPublicKey
      }
    ]
  }
}

References