Create a Virtual Machine
This guide provides step-by-step instructions on how to create a new virtual machine (VM) in Azure using the Azure portal and Azure CLI. Virtual machines are on-demand, scalable computing resources that you can deploy in minutes.
Create via Azure Portal Create via Azure CLI1. Create a VM using the Azure Portal
The Azure portal offers a user-friendly graphical interface to create and manage your Azure resources.
-
Sign in to the Azure portal: Navigate to portal.azure.com and sign in with your Azure account.
-
Navigate to Virtual Machines: In the search bar at the top, type "Virtual machines" and select "Virtual machines" from the search results.
-
Create a new VM: Click on the "+ Create" button and select "Virtual machine".
-
Basics Tab:
- Subscription: Select your Azure subscription.
- Resource group: Create a new one or select an existing one.
- Virtual machine name: Enter a unique name for your VM (e.g.,
myVM-01). - Region: Choose the Azure region where you want to deploy your VM.
- Availability options: Select your preference for availability.
- Security type: Choose "Standard" or "Trusted launch virtual machines".
- Image: Select an operating system image (e.g., "Windows Server 2022 Datacenter: Gen2" or "Ubuntu Server 22.04 LTS").
- Size: Choose a VM size that meets your performance and cost requirements.
- Administrator account:
- For Linux: Select "SSH public key" or "Password". If using SSH keys, provide your public key.
- For Windows: Enter a username and password.
- Inbound port rules: For public access, select "Allow selected ports" and choose "SSH (22)" for Linux or "RDP (3389)" for Windows.
-
Disks Tab: Configure your OS disk and data disks. You can choose disk types like Premium SSD, Standard SSD, or Standard HDD.
-
Networking Tab: Configure the virtual network, subnet, public IP address, and network security group (NSG).
-
Management, Advanced, and Tags Tabs: Review and configure additional settings as needed, such as monitoring, auto-shutdown, and tags.
-
Review + create: Once you have configured all settings, click "Review + create". Azure will validate your configuration.
-
Create: If validation passes, click "Create" to deploy your virtual machine.
2. Create a VM using Azure CLI
The Azure Command-Line Interface (CLI) allows you to manage Azure resources from your terminal.
Prerequisites: Ensure you have Azure CLI installed and are logged in to your Azure account (az login).
Here's a basic command to create a Linux VM:
az vm create \
--resource-group myResourceGroup \
--name myVM-CLI \
--image UbuntuLTS \
--admin-username azureuser \
--generate-ssh-keys
Explanation of parameters:
--resource-group: The name of the resource group to create the VM in.--name: The name of your virtual machine.--image: The OS image to use. Common options includeUbuntuLTS,Win2019Datacenter,CentOS.--admin-username: The username for the administrator account.--generate-ssh-keys: Automatically generates SSH public and private key files if they don't exist. For Windows, you'd use--admin-password.
You can specify many more options, such as VM size, region, disk type, and network settings. For example, to specify a size and location:
az vm create \
--resource-group myResourceGroup \
--name myVM-CLI-Advanced \
--image Debian11 \
--size Standard_B2s \
--location eastus \
--admin-username azureuser \
--generate-ssh-keys
For a comprehensive list of Azure CLI commands for VM creation and their parameters, refer to the Azure CLI VM documentation.
Next Steps
Once your VM is created, you can connect to it, install software, and configure it to run your applications. Explore the following resources: