Setting Up a Linux Virtual Machine on Azure

This tutorial will guide you through the process of creating and configuring a Linux Virtual Machine (VM) in Azure. This is a fundamental step for many cloud-based applications and services.

Prerequisites

Step 1: Create a Resource Group

A resource group is a logical container for your Azure resources. It simplifies management and deployment.

Action: Navigate to the Azure portal, click "Create a resource", search for "Resource group", and click "Create". Fill in the required details such as Subscription, Name (e.g., myLinuxVM-RG), and Region. Click "Review + create" and then "Create".

Step 2: Create a Linux Virtual Machine

Now, let's create the actual Linux VM within your resource group.

Action: In the Azure portal, click "Create a resource", search for "Virtual machine", and click "Create".

Basics Tab

  • Subscription: Select your Azure subscription.
  • Resource group: Choose the resource group you created (e.g., myLinuxVM-RG).
  • Virtual machine name: Enter a name for your VM (e.g., myLinuxVM).
  • Region: Select the same region as your resource group.
  • Availability options: For this tutorial, you can select "No infrastructure redundancy required".
  • Security type: Standard is fine for this example.
  • Image: Choose your preferred Linux distribution. Ubuntu Server 20.04 LTS is a popular choice.
  • Size: Select a VM size based on your needs. For testing, Standard_B1s or Standard_B2s is often sufficient.
  • Administrator account:
    • Authentication type: Choose "SSH public key" for better security.
    • Username: Enter your desired username (e.g., azureuser).
    • SSH public key source: Select "Generate new key pair" and provide a name (e.g., myLinuxVM_key), or use an existing one. Download the private key and store it securely.
  • Inbound port rules: Select "Allow selected ports" and ensure SSH (port 22) is selected.

Disks Tab

For basic setups, the default OS disk settings are usually fine. You can configure data disks if needed later.

Networking Tab

Azure will create a virtual network, subnet, public IP address, and network security group by default. These settings are generally suitable for a basic VM.

Management, Advanced, Tags Tabs

You can explore these tabs for more advanced configurations, but for this tutorial, you can leave the default settings.

Action: Click "Review + create". Azure will validate your configuration. Once validation passes, click "Create".
Note: The VM deployment may take a few minutes. You can monitor the progress in the Azure portal.

Step 3: Connect to Your Linux VM

Once the VM is deployed, you can connect to it using SSH.

  1. Find the Public IP Address: Go to your Virtual Machine's overview page in the Azure portal. You will find the "Public IP address".
  2. Connect via SSH: Open your terminal or SSH client. Use the following command, replacing <your-vm-public-ip> with the IP address you found and <your-username> with the username you set during VM creation. You will also need to specify the path to your private key file.
    ssh -i /path/to/your/private/key.pem @
    If you generated a new key pair and downloaded it, the command would look something like this:
    ssh -i ./myLinuxVM_key.pem azureuser@20.112.123.456
  3. Accept Host Key: The first time you connect, you will be asked to confirm the authenticity of the host. Type yes and press Enter.

You are now connected to your Linux VM running on Azure!

Next Steps

  • Update your package lists and install software: sudo apt update && sudo apt upgrade -y
  • Explore other Azure services to complement your VM, such as Azure Storage or Azure SQL Database.
  • Learn how to secure your virtual machine.