Azure CLI 2 cheatsheet

Azure CLI 2: Resource groups and VMs

8 common Azure CLI 2 tasks.

Create a resource group

Create a container for related resources.

az group create --name my-rg --location westeurope

List resource groups

Show your resource groups.

az group list --output table

Delete a resource group

Delete a resource group and everything inside it.

az group delete --name my-rg --yes --no-wait

Caution: Deletes every resource in the group permanently. Check the name first, and note that --yes skips the confirmation.

Create a Linux VM

Create a VM with SSH keys generated for you.

az vm create --resource-group my-rg --name my-vm --image Ubuntu2204 --admin-username azureuser --generate-ssh-keys

List VMs and their IPs

Show VMs with their public IP addresses and power state.

az vm list --show-details --output table

Stop and deallocate a VM

Deallocate to stop paying for compute. A plain stop keeps billing.

az vm deallocate --resource-group my-rg --name my-vm

Start a VM

Start a stopped or deallocated VM.

az vm start --resource-group my-rg --name my-vm

Open a port on a VM

Allow inbound traffic to a VM's port.

az vm open-port --resource-group my-rg --name my-vm --port 443

Was this page helpful?