Azure Virtual Machines Quickstart

Overview

This guide walks you through creating a Windows or Linux virtual machine (VM) in Azure using three different methods:

By the end of this quickstart you will have a running VM that you can connect to via RDP (Windows) or SSH (Linux).

Prerequisites

Deploy a VM

Azure Portal
Azure CLI
ARM Template

Using Azure Portal

  1. Sign in to the Azure portal.
  2. Click Create a resourceComputeVirtual Machine.
  3. Fill in the required fields:
    • Subscription: Select your subscription.
    • Resource group: Create a new group or select an existing one.
    • Virtual machine name: e.g., myVM
    • Region: Choose a region close to you.
    • Image: Choose Windows Server 2022 or Ubuntu 22.04 LTS.
    • Size: Select a size (e.g., Standard_B1s).
  4. Configure Administrator account and Inbound port rules (RDP for Windows, SSH for Linux).
  5. Click Review + create, then Create. Deployment usually completes in a few minutes.
  6. Once provisioned, navigate to Connect to retrieve RDP/SSH connection details.

Using Azure CLI

Run the following commands in a terminal. Replace placeholder values (e.g., <resource-group>) with your own.

# Create a resource group
az group create --name myResourceGroup --location eastus

# Create a Linux VM
az vm create \
  --resource-group myResourceGroup \
  --name myLinuxVM \
  --image UbuntuLTS \
  --admin-username azureuser \
  --generate-ssh-keys

# Open port 22 for SSH
az vm open-port --resource-group myResourceGroup --name myLinuxVM --port 22

# Create a Windows VM
az vm create \
  --resource-group myResourceGroup \
  --name myWindowsVM \
  --image Win2022Datacenter \
  --admin-username azureadmin \
  --admin-password MyP@ssw0rd! \
  --size Standard_B2s

# Open port 3389 for RDP
az vm open-port --resource-group myResourceGroup --name myWindowsVM --port 3389

Using an ARM Template

Save the following JSON as vm-deploy.json and deploy it with Azure CLI.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": { "type": "string", "defaultValue": "myARMVM" },
    "adminUsername": { "type": "string", "defaultValue": "azureuser" },
    "adminPassword": { "type": "secureString" },
    "location": { "type": "string", "defaultValue": "[resourceGroup().location]" },
    "vmSize": { "type": "string", "defaultValue": "Standard_B1s" },
    "imagePublisher": { "type": "string", "defaultValue": "Canonical" },
    "imageOffer": { "type": "string", "defaultValue": "UbuntuServer" },
    "imageSKU": { "type": "string", "defaultValue": "22_04-lts" }
  },
  "resources": [
    {
      "type": "Microsoft.Compute/virtualMachines",
      "apiVersion": "2022-03-01",
      "name": "[parameters('vmName')]",
      "location": "[parameters('location')]",
      "properties": {
        "hardwareProfile": { "vmSize": "[parameters('vmSize')]" },
        "osProfile": {
          "computerName": "[parameters('vmName')]",
          "adminUsername": "[parameters('adminUsername')]",
          "adminPassword": "[parameters('adminPassword')]"
        },
        "storageProfile": {
          "imageReference": {
            "publisher": "[parameters('imagePublisher')]",
            "offer": "[parameters('imageOffer')]",
            "sku": "[parameters('imageSKU')]",
            "version": "latest"
          },
          "osDisk": {
            "createOption": "FromImage",
            "diskSizeGB": 30
          }
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', concat(parameters('vmName'), 'NIC'))]"
            }
          ]
        }
      }
    },
    {
      "type": "Microsoft.Network/networkInterfaces",
      "apiVersion": "2022-05-01",
      "name": "[concat(parameters('vmName'), 'NIC')]",
      "location": "[parameters('location')]",
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "subnet": {
                "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', concat(parameters('vmName'), 'VNET'), 'default')]"
              },
              "privateIPAllocationMethod": "Dynamic",
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses', concat(parameters('vmName'), 'PIP'))]"
              }
            }
          }
        ]
      }
    },
    {
      "type": "Microsoft.Network/publicIPAddresses",
      "apiVersion": "2022-05-01",
      "name": "[concat(parameters('vmName'), 'PIP')]",
      "location": "[parameters('location')]",
      "properties": { "publicIPAllocationMethod": "Dynamic" }
    },
    {
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2022-05-01",
      "name": "[concat(parameters('vmName'), 'VNET')]",
      "location": "[parameters('location')]",
      "properties": {
        "addressSpace": { "addressPrefixes": ["10.0.0.0/16"] },
        "subnets": [
          {
            "name": "default",
            "properties": { "addressPrefix": "10.0.0.0/24" }
          }
        ]
      }
    }
  ],
  "outputs": {
    "adminUsername": { "type": "string", "value": "[parameters('adminUsername')]" },
    "publicIP": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.Network/publicIPAddresses', concat(parameters('vmName'), 'PIP'))).dnsSettings.fqdn]"
    }
  }
}

Deploy with:

az deployment group create \
  --resource-group myResourceGroup \
  --template-file vm-deploy.json \
  --parameters adminPassword=MyP@ssw0rd!

Clean Up Resources

To avoid incurring charges, delete the resource group when you are finished:

az group delete --name myResourceGroup --yes --no-wait