Forum Discussion

danielcregg's avatar
danielcregg
Copper Contributor
Feb 18, 2022
Solved

Azure CLI create VM and assign it a password AND a ssh key for login?

How do I create a VM using Azure CLI and assign it a password AND a ssh key for login?

Here is the command I want to use but it just creates the ssh key and ignores creating the password. 

 

az vm create --resource-group VMResourceGroup --name ubuntuVM --image Canonical:0001-com-ubuntu-server-impish:21_10-gen2:21.10.202202010 --size Standard_B1s --os-disk-size-gb 64 --public-ip-sku Basic --admin-username xman --admin-password 'mypassword*1'

 

Thanks 

Regards

Daniel

  • Based on the info in the docs, it looks like you need to set the auth type to all to allow both SSH & password:
    --authentication-type
    Type of authentication to use with the VM. Defaults to password for Windows and SSH public key for Linux. "all" enables both ssh and password authentication.

    accepted values: all, password, ssh
  • Davy_A's avatar
    Davy_A
    Brass Contributor
    Based on the info in the docs, it looks like you need to set the auth type to all to allow both SSH & password:
    --authentication-type
    Type of authentication to use with the VM. Defaults to password for Windows and SSH public key for Linux. "all" enables both ssh and password authentication.

    accepted values: all, password, ssh
    • danielcregg's avatar
      danielcregg
      Copper Contributor
      Thanks, this works.
      To create a free Ubuntu VM with password and ssh keys I create a resource group called myResourceGroup and I run the following command:

      az vm create --resource-group myResourceGroup --name myVM --image Canonical:0001-com-ubuntu-server-impish:21_10-gen2:21.10.202202010 --size Standard_B1s --os-disk-size-gb 64 --public-ip-sku Basic --authentication-type all --generate-ssh-keys --admin-username azureuser --admin-password SoMePaSsWoRd1

Resources