Create a Virtual Machine in Azure
Note: This guide walks you through creating a Linux virtual machine using the Azure portal. You can also create VMs using Azure CLI, PowerShell, ARM templates, or Bicep.
This document provides a step-by-step guide to help you create your first Azure virtual machine (VM) using the Azure portal. Azure VMs enable you to create and use virtual machines in the Azure cloud.
Prerequisites
Before you begin, you need an Azure subscription. If you don't have one, you can create a free account.
Steps to Create a Virtual Machine
Open your web browser and navigate to https://portal.azure.com/. Sign in with your Azure account credentials.
In the Azure portal, search for "Virtual machines" and select it from the services list. Click the "+ Create" button, then select "Virtual machine".
Alternatively, you can click the "+ Create a resource" button on the Azure portal home page, then select "Compute" > "Virtual machine".
On the Basics tab, configure the following settings:
- Subscription: Select the Azure subscription you want to use.
- Resource group: Create a new resource group or select an existing one. A resource group is a logical container for your Azure resources.
- Virtual machine name: Enter a unique name for your VM (e.g.,
myAzureVM). - Region: Select the Azure region where you want to deploy your VM. Choose a region close to your users for lower latency.
- Availability options: For this basic tutorial, select "No infrastructure redundancy required".
- Security type: For this basic tutorial, select "Standard".
- Image: Select an operating system image. For this example, choose "Ubuntu Server 20.04 LTS - Gen2".
- VM architecture: Select "x64".
- Size: Choose a VM size that meets your performance and cost requirements. For this tutorial, select
Standard_B2s. - Administrator account:
- Authentication type: Select "SSH public key".
- Username: Enter an administrator username (e.g.,
azureuser). - SSH public key source: Select "Generate new key pair".
- Key pair name: Enter a name for your key pair (e.g.,
myAzureKey). Azure will generate and store the public and private keys for you.
- Inbound port rules:
- Public inbound ports: Select "Allow selected ports".
- Select inbound ports: Choose "SSH (22)".
On the Disks tab, you can configure the OS disk and data disks.
- OS disk type: For better performance, select "Premium SSD". For cost savings, choose "Standard SSD" or "Standard HDD". We'll select "Premium SSD" for this example.
- You can optionally add data disks here if needed.
On the Networking tab, you can configure the virtual network, subnet, public IP address, and network security group (NSG).
- Azure will create default values for these if you don't specify them. For this example, the defaults are fine.
- Ensure that "Public inbound ports" is set to "Allow selected ports" and "SSH (22)" is selected in the Network security group section.
You can configure additional settings on the Management, Advanced, and Tags tabs as needed. For this basic setup, you can leave these as default.
On the Review + create tab, Azure will validate your configuration. Once the validation passes, review the summary of your VM's settings.
Click the Create button to deploy your virtual machine.
Once the deployment is complete, navigate to your virtual machine resource in the Azure portal.
On the Overview page, you will find the public IP address for your VM. Use an SSH client (like PuTTY on Windows or the built-in `ssh` command on Linux/macOS) to connect:
ssh azureuser@<your-public-ip-address>
If you generated a new key pair, Azure will prompt you to download the private key (.pem file) during the creation process. You will need this file to connect.
Ensure your private key file has the correct permissions (e.g., chmod 400 myAzureKey.pem on Linux/macOS) before connecting.
Example connection with a downloaded private key:
ssh -i /path/to/your/myAzureKey.pem azureuser@<your-public-ip-address>
Tip: For Windows VMs, you'll typically use Remote Desktop Protocol (RDP) on port 3389 to connect. Ensure RDP is allowed in the Network Security Group.