Azure Virtual Machines Tutorial

Learn how to create and manage virtual machines in Azure.

Introduction to Azure Virtual Machines

Azure Virtual Machines (VMs) provide on-demand, scalable computing resources. You can use Azure VMs to deploy and run applications that require greater control over the operating system than do solutions like containers, or that need to run in a specific environment. This tutorial will guide you through the essential steps of creating and configuring an Azure VM.

Prerequisites

Before you begin, ensure you have:

Step 1: Create a Virtual Machine

We'll walk through creating a Linux VM using the Azure portal. The steps are similar for Windows VMs.

  1. Sign in to the Azure portal.

    Open your web browser and go to https://portal.azure.com/. Sign in with your Azure account.

  2. Navigate to Virtual machines.

    In the Azure portal search bar, type "Virtual machines" and select it from the services list.

  3. Click "Create".

    On the Virtual machines page, click the "+ Create" button and then select "Virtual machine".

  4. Configure basic settings.

    On the "Create a virtual machine" page, you'll need to fill out the following:

    • Subscription: Select your Azure subscription.
    • Resource group: Click "Create new" and give it a name (e.g., myResourceGroup). Resource groups help organize Azure resources.
    • Virtual machine name: Enter a unique name for your VM (e.g., myVM).
    • Region: Choose the Azure region closest to you or your users.
    • Availability options: For this tutorial, you can leave it as "No infrastructure redundancy required".
    • Security type: Select "Standard".
    • Image: Choose an operating system image. For this tutorial, select "Ubuntu Server 20.04 LTS - Gen2".
    • Size: Select a VM size. You can choose a smaller size like Standard_B1s for cost-effectiveness.
    • Username: Enter a username for the administrator account (e.g., azureuser).
    • Authentication type: Select "SSH public key" (recommended for Linux) or "Password". If using SSH keys, provide your public key. If using password, enter and confirm a strong password.
  5. Configure disks.

    For this tutorial, the default settings for disks (e.g., OS disk type: Premium SSD) are fine.

  6. Configure networking.

    Defaults are generally suitable. Ensure you have a Virtual network and Subnet created or allow Azure to create them.

  7. Review and Create.

    Click on the "Review + create" button. Azure will validate your configuration. Once validation passes, click "Create".

Step 2: Connect to your Virtual Machine

After the VM is deployed, you can connect to it.

Connecting via SSH (Linux)

If you created a Linux VM and used SSH key authentication:

  1. Find your VM's public IP address.

    Navigate back to your Virtual machine's overview page in the Azure portal. The public IP address will be listed there.

  2. Open your terminal or SSH client.

    Use the following command, replacing <your_username>, <your_private_key_path>, and <public_ip_address> with your actual values:

    ssh -i <your_private_key_path> <your_username>@<public_ip_address>

    If you used a password, the command would be:

    ssh <your_username>@<public_ip_address>

    You will be prompted to enter your password or confirm the connection.

Connecting via RDP (Windows)

If you created a Windows VM:

  1. Download the RDP file.

    On the VM's overview page in the Azure portal, click the "Connect" button and select "RDP". Download the RDP file.

  2. Open the RDP file.

    Double-click the downloaded file. You will be prompted for credentials. Use the username and password you set during VM creation.

Security Note: For production environments, it's highly recommended to use SSH keys for Linux VMs and secure your RDP access for Windows VMs by restricting network access or using Azure Bastion.

Step 3: Basic VM Management

Once connected, you can start managing your VM. Here are a few common tasks:

Updating your VM

It's crucial to keep your VM's operating system and software up-to-date.

Stopping and Starting your VM

To save costs, you can stop your VM when not in use. Note that stopping deallocates the VM, freeing up compute resources.

Restarting your VM

You can restart your VM from the Azure portal or by using commands within the VM.

Next Steps

This tutorial covered the basics of creating and connecting to an Azure Virtual Machine. Here are some ideas for further learning:

Congratulations on successfully creating and connecting to your first Azure Virtual Machine!