LinuxCommandLibrary

az-vm

Manage Azure Virtual Machines

TLDR

Display a table of available Virtual Machines

$ az vm list --output table
copy

Create a virtual machine using the default Ubuntu image and generate SSH keys
$ az vm create [[-g|--resource-group]] [rg] [[-n|--name]] [vm_name] --image [UbuntuLTS] --admin-user [azureuser] --generate-ssh-keys
copy

Stop a Virtual Machine
$ az vm stop [[-g|--resource-group]] [rg] [[-n|--name]] [vm_name]
copy

Deallocate a Virtual Machine
$ az vm deallocate [[-g|--resource-group]] [rg] [[-n|--name]] [vm_name]
copy

Start a Virtual Machine
$ az vm start [[-g|--resource-group]] [rg] [[-n|--name]] [vm_name]
copy

Restart a Virtual Machine
$ az vm restart [[-g|--resource-group]] [rg] [[-n|--name]] [vm_name]
copy

List VM images available in the Azure Marketplace
$ az vm image list
copy

SYNOPSIS

az vm <command> [--resource-group] [--name] [--subscription] [--location] [--size] [--debug] [--help] [--output (-o)] [--query (-q)] [--verbose] [--no-wait]

PARAMETERS

--debug
    Increase logging verbosity to show all debug logs.

--help -h
    Show help message and exit.

--output -o
    Output format (json, jsonc, table, tsv, yaml).

--query -q
    JMESPath query string for output filtering.

--verbose
    Increase logging verbosity (use --debug for full logs).

--resource-group -g
    Name of the resource group (configurable default).

--name -n
    Name of the virtual machine.

--subscription
    Subscription ID or name.

--location -l
    Azure region for resources.

--size
    VM size (e.g., Standard_DS2_v2).

--no-wait
    Do not wait for completion (async mode).

--tags
    Space-separated tags in 'key=value' format.

DESCRIPTION

The az vm command is a key component of the Azure Command-Line Interface (CLI), a cross-platform tool for managing Azure resources from Linux, macOS, or Windows. It serves as a command group with numerous subcommands to handle virtual machines (VMs), supporting both Linux and Windows instances.

Core operations include creating VMs from images or marketplaces, listing and showing VM details, starting, stopping, restarting, deallocating, resizing, updating, and deleting them. Advanced features cover VM extensions, availability sets/ zones, disks, networking, backups, and diagnostics.

Requires Azure CLI installation and authentication via az login. Most subcommands share options like --resource-group and --name for targeting resources. Ideal for automation, scripting, and DevOps workflows in cloud environments.

Example: az vm create --resource-group myRG --name myVM --image Ubuntu2204 --generate-ssh-keys. Use az vm --help or az vm <subcommand> --help for details. Enhances productivity over portal for bulk or repeated tasks.

CAVEATS

Requires Azure CLI 2.0+ installed, az login authentication, and appropriate RBAC permissions. Some operations (e.g., resize) have constraints like VM state or series compatibility. Not for on-premises VMs; Azure-only. Rate limits apply to API calls.

KEY SUBCOMMANDS

create, list, show, start, stop, restart, deallocate, delete, resize, update, extension, run-command, image.

PREREQUISITES

Install via curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash. Login with az login. Set defaults: az configure --defaults group=myRG location=eastus.

HISTORY

Introduced in Azure CLI 2.0 (2017) as part of Microsoft's shift from xplat-cli. Evolved with Azure VM features like confidential computing (2020+), spot VMs, and hybrid capabilities. Regular updates via az upgrade align with Azure SDK changes.

SEE ALSO

az(1), az-group(1), ssh(1), systemctl(1)

Copied to clipboard