Quickstart: Create a Linux Virtual Machine in Azure

This quickstart guide shows you how to create a Linux virtual machine (VM) in Azure using the Azure portal.

Before you begin

Note: You'll need an active Azure account. If you don't have one, you can create a free account before you begin.

Sign in to Azure

Sign in to the Azure portal with your Azure account.

Create a virtual machine

1. Create a resource

In the Azure portal, search for and select Virtual machines.

On the Virtual machines page, select Create then Virtual machine.

2. Configure basic settings

On the Create a virtual machine page, use the Basics tab to configure your VM.

  • Subscription: Select your Azure subscription.
  • Resource group: Select Create new, enter a name like myResourceGroupVM, and then select OK.
  • Virtual machine name: Enter a name for your VM, like myVM.
  • Region: Select a region near you or your team.
  • Availability options: Select No infrastructure redundancy required.
  • Security type: Select Standard.
  • Image: Select Ubuntu Server 22.04 LTS - Gen2.
  • VM architecture: Select x64.
  • Size: Select Standard_B1s (or another size based on your needs).
  • Administrator account:
    • Authentication type: Select SSH public key.
    • Username: Enter a username, like azureuser.
    • SSH public key source: Select Generate new key pair.
    • Key pair name: Enter a name for the key pair, like myKey.
  • Inbound port rules:
    • Public inbound ports: Select Allow selected ports.
    • Select inbound ports: Select SSH (22).
Tip: You can also choose SSH public key from existing if you already have a key pair. For an SSH public key, ensure it's in the correct format (e.g., PEM). If you're using Azure CLI or PowerShell, you can generate one using ssh-keygen.

3. Configure storage

On the Disks tab, leave the default settings and select Next: Networking >.

4. Configure networking

On the Networking tab, leave the default settings and select Next: Management >.

5. Configure management

On the Management tab, leave the default settings and select Next: Advanced >.

6. Configure advanced settings

On the Advanced tab, leave the default settings and select Next: Tags >.

7. Add tags

On the Tags tab, you can optionally add tags to organize your resources. Then, select Next: Review + create >.

8. Review and create

On the Review + create tab, Azure will validate your configuration. Once validation passes, you'll see a summary of your VM's settings. Select Create.

Important: When prompted to download your private key and create the resource, make sure to download your private key (e.g., myKey.pem) and store it securely. You'll need it to connect to your VM.

9. Download private key and deploy

A download link for your private key will appear. Download it and save it to a secure location.

The deployment will take a few minutes. You can monitor the progress in the Azure portal.

Connect to your virtual machine

Once the deployment is complete, go to the resource overview for your virtual machine.

Find the Public IP address of your VM and copy it.

Open an SSH client and connect to your VM using the following command, replacing with your VM's public IP and ~/.ssh/myKey.pem with the path to your private key file:

ssh -i ~/.ssh/myKey.pem azureuser@<your_public_ip_address>

If prompted to continue connecting, type yes and press Enter.

Troubleshooting: If you can't connect, ensure that port 22 is open in your Network Security Group (NSG) and that your SSH client is configured correctly.

Next steps