Quickstart: Create a Linux Virtual Machine in Azure
This guide will walk you through the steps to create a basic Linux virtual machine (VM) in Azure using the Azure portal.
Introduction
Azure Virtual Machines provide on-demand, scalable computing resources. You can use Azure VMs to deploy and run applications, host websites, and much more. This quickstart focuses on creating a Linux VM, specifically Ubuntu LTS, with the most common configurations.
Prerequisites
- An Azure account with an active subscription. If you don't have one, you can create a free account.
Create the VM
Follow these steps to create your Linux VM:
Sign in to the Azure portal: Navigate to https://portal.azure.com/ and sign in with your Azure account.
Create a resource: On the Azure portal home page, select "Create a resource".
Search for Virtual Machine: In the search bar, type "Virtual machine" and select "Virtual machine" from the results.
Click "Create": On the Virtual machines page, click the "Create" button and then select "Virtual machine".
Basics Tab:
- Subscription: Select your Azure subscription.
- Resource group: Click "Create new" and enter a name for your resource group (e.g.,
myResourceGroup). - Virtual machine name: Enter a unique name for your VM (e.g.,
myUbuntuVM). - Region: Choose a region closest to you or your users.
- Availability options: Keep the default "No infrastructure redundancy required".
- Security type: Keep the default "Standard".
- Image: Select "Ubuntu Server 22.04 LTS - Gen2".
- Size: Choose a VM size. For this quickstart, "Standard_B1s" is a cost-effective option.
- Administrator account:
- Authentication type: Select "SSH public key".
- Username: Enter a 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.,
myUbuntuVM_key).
- Inbound port rules: For "Public inbound ports", select "Allow selected ports". For "Select inbound ports", ensure "SSH (22)" is selected.
Disks Tab:
- OS disk type: Keep the default "Standard SSD".
Networking Tab:
- The default settings for virtual network, subnet, public IP, and NIC network security group are sufficient for this quickstart. Ensure "None" is selected for Load balancing.
Management, Advanced, and Tags Tabs: For this quickstart, you can leave the default settings on these tabs.
Review + create: Click the "Review + create" button. After validation passes, click "Create".
When the deployment is complete, you will see a notification. Click "Go to resource" to view your new virtual machine.
Connect to the VM
Once the VM is deployed, you can connect to it using SSH.
Get the public IP address: On the VM's overview page, find the "Public IP address" and copy it.
Download the private key: If you generated a new key pair, you will be prompted to download the private key. Ensure you save this file securely, as it is required to connect to your VM.
Connect via SSH: Open your terminal or SSH client and run the following command, replacing <your_private_key_path> with the path to your downloaded private key file and <public_ip_address> with the public IP address of your VM.
ssh -i <your_private_key_path> azureuser@<public_ip_address>
For example:
ssh -i ~/.ssh/myUbuntuVM_key.pem azureuser@20.102.47.190
Accept host key: If prompted, type yes to trust the host and establish the connection.
You should now be connected to your Azure Linux VM!
Clean up resources
When you are finished with your VM, you can delete the resource group and all its associated resources to avoid ongoing charges.
Navigate to Resource Groups: In the Azure portal, search for and select "Resource groups".
Select your resource group: Click on the resource group you created (e.g., myResourceGroup).
Delete resource group: Click the "Delete resource group" button at the top. Confirm the deletion by typing the resource group name and clicking "Delete".
This will remove your virtual machine and all associated resources.