Skip to main content

Command Palette

Search for a command to run...

Create a Linux virtual machine in the Azure portal

Published
4 min read

Introduction

Microsoft Azure provides a powerful cloud platform for deploying virtual machines (VMs) running Linux distributions. Whether you're setting up a development environment, hosting a web server, or running automated scripts, creating a Linux VM in Azure is a straightforward process. In continuation of our series on creation of virtual machines in Azure, this step-by-step guide will walk you through creating and connecting to a Linux VM using the Azure Portal.

Prerequisites

Before you begin, ensure you have:
An active Azure account. SSH key pair (Recommended for secure authentication)
Basic familiarity with Linux and Azure Portal

Step 1: Sign in to the Azure Portal

  1. Open a web browser, type in the Azure portal url and navigate to the Azure Portal.

  2. Sign in with your Azure credentials.

    Step 2: Create a New Virtual Machine

    1. Enter virtual machines in the Azure search bar.

    2. Under Services, select Virtual machines.

    3. In the Virtual machines page, select Create and then Virtual machine. The Create a virtual machine page opens.

      Step 3: Configure Basic VM Settings

      In the Basics tab, under Project details;

      1. Project Details

      • Subscription: Select your Azure subscription.

      • Resource Group:

        • Choose an existing group or

        • Click "Create new" and enter a name

2. Instance Details

  • Virtual machine name: Enter a unique name (e.g., my-linux-vm).

  • Region: Select the nearest Azure region (e.g., East US).

  • Availability options: No infrastructure redundancy required (for testing).

  • Image: Choose a Linux distribution (e.g., Ubuntu Server 22.04 LTS).

  • Size: Select a VM size (e.g., Standard B1s – 1 vCPU, 1 GiB RAM for lightweight workloads).

3. Administrator Account

  • Authentication type:

    • SSH public key (Recommended for security) or

    • Password (Less secure).

  • Username: Enter a login name (e.g., azureuser).

  • SSH public key source:

    • Generate new key pair (Azure creates and downloads a private key) or

    • Use existing public key (Paste your .pub key).

4. Inbound Port Rules

Under Inbound port rules > Public inbound ports, choose Allow selected ports and then select from the drop-down.

  • Select inbound ports:

    • SSH (22) – Required for remote access.

    • (Optional) HTTP (80) / HTTPS (443) if hosting a web server.

Leave the remaining defaults and then select the Review + create button at the bottom of the page.

5. On the Create a virtual machine page, you can see the details about the VM you are about to create. When you are ready, select Create.

  1. When the Generate new key pair window opens, select Download private key and create resource. Your key file will be download as myKey.pem. Make sure you know where the .pem file was downloaded; you will need the path to it in the next step.

  1. When the deployment is finished, select Go to resource.

  1. On the page for your new VM, select the public IP address and copy it to your clipboard.

Connect to virtual machine

Create an SSH connection with the VM.

  1. If you are on a Mac or Linux machine, open a Bash prompt and set read-only permission on the .pem file using chmod 400 ~/Downloads/myKey.pem. If you are on a Windows machine, open a PowerShell prompt.

  1. At your prompt, open an SSH connection to your virtual machine. Replace the IP address with the one from your VM, and replace the path to the .pem with the path to where the key file was downloaded

Install web server

To see your VM in action, install the NGINX web server. From your SSH session, update your package sources and then install the latest NGINX package.

When done, type exit to leave the SSH session.

View the web server in action

Use a web browser of your choice to view the default NGINX welcome page. Type the public IP address of the VM as the web address. The public IP address can be found on the VM overview page or as part of the SSH connection string you used earlier.

/