What is Azure CLI ?
The Azure command-line interface (Azure CLI) is a set of commands used to create and manage Azure resources. The Azure CLI is available across Azure services and is designed to get you working quickly with Azure, with an emphasis on automation.
Documentation here
Create a Linux VM with the Azure CLI
The Azure CLI includes the vm
command to work with virtual machines in Azure. We can supply several subcommands to do specific tasks. The most common include:
Sub-command | Description |
---|---|
create | Create a new virtual machine |
deallocate | Deallocate a virtual machine |
delete | Delete a virtual machine |
list | List the created virtual machines in your subscription |
open-port | Open a specific network port for inbound traffic |
restart | Restart a virtual machine |
show | Get the details for a virtual machine |
start | Start a stopped virtual machine |
stop | Stop a running virtual machine |
update | Update a property of a virtual machine |
Create new VM Using AZ CLI :-
az vm create --resource-group [resource group name] --location westus --name OsamaVM
--image UbuntuLTS --admin-username osama--generate-ssh-keys --verbose


After creating the vmware , Public IP is assigned to create VM, to check the Public IP

Another way to check the IP by using the below command :-
az vm list-ip-addresses -n OsamaVM -o table
You could ports using AZ CLI for example
az vm open-port --port 80 --resource-group learn-9c22c502-355e-437b-9682-eb54b8c48e1c --name OsamaVM
You can connect SSH to the VM Using the below command :-

There are pre defined image avaliable from Azure you can check them by :-

Or you can check the Avaliable Images in certain location, here you could find different between locations :-

For example also, the below command shows the images that has been created only By Microsoft :-
az vm image list --publisher Microsoft --output table --all

One More thing , To resize a VM, we use the vm resize
command. For example, perhaps we find our VM is underpowered for the task we want it to perform. We could bump it up to a D2s_v3 where it has 2 vCores and 8 GB of memory. Type this command in Cloud Shell:
az vm resize --resource-group test-7223198d-cbdf-4fb7-bfd9-b609eaca3671 --name OsamaVM--size Standard_D2s_v3

Cheers
Enjoy
Osama