Quickstart: Create a Linux virtual machine in Azure
This tutorial guides you through the process of creating your first Linux virtual machine (VM) in Azure using the Azure portal. This is a fundamental step for many cloud deployments.
1 Create a Resource Group
A resource group is a logical container that holds related Azure resources. All resources for the VM will be placed in this group.
- Sign in to the Azure portal.
- In the portal, search for and select "Resource groups".
- On the "Resource groups" page, select "Create".
- Subscription: Choose your Azure subscription.
- Resource group name: Enter a unique name, e.g.,
my-vm-rg
. - Region: Select a region close to you, e.g.,
East US
. - Click "Review + create", then "Create".
2 Create a Virtual Machine
Now, let's create the virtual machine itself.
- In the Azure portal, search for and select "Virtual machines".
- On the "Virtual machines" page, select "Create" and then "Azure virtual machine".
- Basics tab:
- Subscription: Your subscription.
- Resource group: Select the resource group you created (e.g.,
my-vm-rg
). - Virtual machine name: Enter a name for your VM, e.g.,
my-vm
. - Region: Same region as your resource group.
- Availability options: Keep the default.
- Security type: Standard.
- Image: Select
Ubuntu Server 20.04 LTS - Gen2
. - Size: Choose a suitable size, e.g.,
Standard B1s
(cost-effective for testing). - Administrator account:
- Authentication type: SSH public key.
- Username: Enter a username, e.g.,
azureuser
. - SSH public key source:
Generate new key pair
. - Key pair name: Enter a name, e.g.,
myvmkey
.
- Inbound port rules: Select
Allow selected ports
and chooseSSH (22)
.
- Click "Next: Disks >". Keep defaults and click "Next: Networking >".
- Click "Next: Management >", then "Next: Advanced >", then "Next: Tags >".
- Click "Review + create". Once validation passes, click "Create".
Deployment may take a few minutes. You can monitor the progress in the portal.
Note: You will be prompted to download the SSH private key. Save this file securely! You will need it to connect to your VM.
3 Connect to Your Virtual Machine
Once the VM is deployed, you can connect to it using SSH.
- Navigate back to the "Virtual machines" page and select your newly created VM (e.g.,
my-vm
). - On the VM's overview page, find the Public IP address and copy it.
- Open a terminal or SSH client on your local machine.
- Navigate to the directory where you saved your SSH private key (e.g.,
~/.ssh/
). - Use the following command, replacing
<your-private-key-file.pem>
with the name of your downloaded private key file and<public-ip-address>
with the VM's public IP:ssh -i <your-private-key-file.pem> azureuser@<public-ip-address>
- When prompted to confirm the host authenticity, type
yes
and press Enter.
You should now be connected to your Azure virtual machine!
4 Clean Up Resources
To avoid ongoing charges, it's important to delete resources you no longer need.
- In the Azure portal, navigate to your resource group (e.g.,
my-vm-rg
). - On the resource group's page, click "Delete resource group".
- Confirm the deletion by typing the resource group name and clicking "Delete".
This will delete the VM, its associated network interface, disk, and public IP address.