Deploy Azure Virtual Machines
On this page
Overview
Azure Virtual Machines (VMs) provide scalable, on-demand computing resources. This guide walks you through four common deployment methods:
- Azure Portal (graphical UI)
- Azure CLI (cross‑platform command line)
- Azure PowerShell (Windows‑focused scripting)
- Azure Resource Manager (ARM) templates (infrastructure as code)
Prerequisites
- An active Azure subscription.
- Permission to create resources in the target resource group.
- For CLI/PowerShell:
az
orAz
module installed. - Optional: SSH key pair (Linux) or Windows admin password.
Deploy via Azure Portal
- Sign in to the Azure portal.
- Click Create a resource > Compute > Virtual machine.
- Configure the basics:
- Subscription, Resource group, VM name
- Region, Availability options
- Image (e.g., Ubuntu 22.04 LTS)
- Size (e.g., Standard_B2s)
- Set up authentication (SSH public key or password).
- Review networking, management, and advanced settings as needed.
- Click Review + create, then Create.
Provisioning typically takes 2‑5 minutes.
Deploy via Azure CLI
Run the following command in Bash, PowerShell, or a Cloud Shell session:
az vm create \
--resource-group MyResourceGroup \
--name MyVm01 \
--image UbuntuLTS \
--size Standard_B2s \
--admin-username azureuser \
--ssh-key-values ~/.ssh/id_rsa.pub \
--tags Project=Demo Environment=Dev
To open an SSH session after creation:
az vm ssh --resource-group MyResourceGroup --name MyVm01
Deploy via Azure PowerShell
Open a PowerShell prompt with the Az
module loaded:
Connect-AzAccount
New-AzResourceGroup -Name "MyResourceGroup" -Location "EastUS"
$cred = Get-Credential -Message "Enter a local admin password"
New-AzVM `
-ResourceGroupName "MyResourceGroup" `
-Name "MyVm01" `
-Location "EastUS" `
-VirtualNetworkName "MyVnet" `
-SubnetName "MySubnet" `
-SecurityGroupName "MyNSG" `
-PublicIpAddressName "MyPublicIP" `
-OpenPorts 22 `
-Image "Canonical:UbuntuServer:22_04-lts:latest" `
-Size "Standard_B2s" `
-Credential $cred
Deploy via ARM Template
Save the following JSON as vm-deploy.json
and run:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {"type":"string","defaultValue":"myVm"},
"adminUsername": {"type":"string","defaultValue":"azureuser"},
"adminPassword": {"type":"secureString"}
},
"resources": [
{
"type":"Microsoft.Compute/virtualMachines",
"apiVersion":"2022-08-01",
"name": "[parameters('vmName')]",
"location": "[resourceGroup().location]",
"properties": {
"hardwareProfile": { "vmSize": "Standard_B2s" },
"osProfile": {
"computerName": "[parameters('vmName')]",
"adminUsername": "[parameters('adminUsername')]",
"adminPassword": "[parameters('adminPassword')]"
},
"storageProfile": {
"imageReference": {
"publisher":"Canonical",
"offer":"UbuntuServer",
"sku":"22_04-lts",
"version":"latest"
},
"osDisk": {
"createOption":"FromImage",
"managedDisk": { "storageAccountType":"Standard_LRS" }
}
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces','myNic')]"
}
]
}
}
}
]
}
Deploy with:
az deployment group create \
--resource-group MyResourceGroup \
--template-file vm-deploy.json \
--parameters adminPassword=MySecretP@ssw0rd