Quickstart: Create and Manage a Linux Virtual Machine in Azure
This guide walks you through the essential steps to create, connect to, and manage a Linux virtual machine (VM) in Azure using the Azure CLI.
Prerequisites
- An Azure account with an active subscription. If you don't have one, create a free account before you begin.
- Azure CLI installed. You can install it from here.
Step 1: Log in to Azure
Open your terminal or command prompt and log in to Azure.
This command opens a browser window for you to authenticate your Azure account.
Step 2: Create a Resource Group
Create a resource group to hold your VM and related resources.
Replace MyResourceGroup
with your desired resource group name and eastus
with your preferred Azure region.
Step 3: Create a Virtual Machine
Create the Linux VM.
This command creates a VM named MyLinuxVM
with the Ubuntu 22.04 LTS image. It also creates SSH keys for authentication and sets the admin username to azureuser
.
You can choose from various VM images. To see a list of available images, run:
Step 4: Connect to the Virtual Machine
Connect to your VM using SSH.
Replace azureuser
with your admin username and 20.118.23.123
with the public IP address of your VM. The IP address will be displayed after the az vm create
command, or you can retrieve it using:
Step 5: Manage the Virtual Machine
Once connected, you can manage your Linux VM like any other Linux server.
View VM details:
Stop the VM:
Start the VM:
Deallocate the VM (stops billing for compute):
Step 6: Clean up Resources
Delete the resource group and all its resources when you're done.
This will remove the VM, its network interface, disk, and public IP address.
Next Steps
- Learn more about managing Linux VMs in Azure.
- Explore customizing VM configurations.
- Discover Azure networking features.