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.

  1. Sign in to the Azure portal.
  2. In the portal, search for and select "Resource groups".
  3. On the "Resource groups" page, select "Create".
  4. Subscription: Choose your Azure subscription.
  5. Resource group name: Enter a unique name, e.g., my-vm-rg.
  6. Region: Select a region close to you, e.g., East US.
  7. Click "Review + create", then "Create".

2 Create a Virtual Machine

Now, let's create the virtual machine itself.

  1. In the Azure portal, search for and select "Virtual machines".
  2. On the "Virtual machines" page, select "Create" and then "Azure virtual machine".
  3. 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 choose SSH (22).
  4. Click "Next: Disks >". Keep defaults and click "Next: Networking >".
  5. Click "Next: Management >", then "Next: Advanced >", then "Next: Tags >".
  6. 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.

  1. Navigate back to the "Virtual machines" page and select your newly created VM (e.g., my-vm).
  2. On the VM's overview page, find the Public IP address and copy it.
  3. Open a terminal or SSH client on your local machine.
  4. Navigate to the directory where you saved your SSH private key (e.g., ~/.ssh/).
  5. 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>
  6. 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.

  1. In the Azure portal, navigate to your resource group (e.g., my-vm-rg).
  2. On the resource group's page, click "Delete resource group".
  3. 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.