# Create a Linux virtual machine in the Azure portal

**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**.[  
](https://azure.microsoft.com/free/)✔ **SSH** [**key pair**](https://azure.microsoft.com/free/) (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 Porta**[**l**](https://portal.azure.com/).
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743086076803/5b0fdfb2-8e3f-49b5-a133-829ff68db54d.png align="center")
    
2. Sign in with your Azure credentials.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743086115772/bed68ddc-741a-4bf4-8505-b56b82524f26.png align="center")
    
    **Step 2: Create a New Virtual Machine**
    
    1. Enter *virtual machines* in the Azure search bar.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743086339871/715c1ec4-ecd7-4270-be93-9435cd7daacf.png align="center")
        
    2. Under **Services**, select **Virtual machines**.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743086417780/32a498a1-df98-4dc3-ac68-26efa1a5dc67.png align="center")
        
    3. In the **Virtual machines** page, select **Create** and then **Virtual machine**. The **Create a virtual machine** page opens.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743086477435/93b177b0-278f-4aef-a830-2bd40afa6b0f.png align="center")
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743086637311/05e926c2-3484-4530-8c8c-26dd57aed407.png align="center")
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743086754733/567ffbe4-ed5c-4183-8a6c-c46c32a8c7e1.png align="center")
        
        **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
                
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743087432758/4e9c56e0-e959-4e0a-a355-e58f6a784199.png align="center")
        
        **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).
            
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743088216638/d510b031-add5-474a-8e82-7fa7b5e88e35.png align="center")
        
        **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).
                
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743088892397/c2b180ce-f482-4ea1-9549-490ea361711a.png align="center")
        
        **4\. Inbound Port Rules**
        
        Under **Inbound port rules** &gt; **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.
                
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743089186442/0fd271d6-bc68-43e3-b8dd-9f14911fd910.png align="center")
        
        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**.
        
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743089557867/e032c5f8-de03-4aa7-b46c-68ad2ad3c32f.png align="center")
    
    6. 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.
        
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743089888887/38a9786c-994c-47aa-be11-086918695083.png align="center")
    
    7. When the deployment is finished, select **Go to resource**.
        
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743090153511/d5b101bf-d215-4a50-9718-f761043a2d10.png align="center")
    
    8. On the page for your new VM, select the public IP address and copy it to your clipboard.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743090373304/44a2e6c8-25a0-49af-80dc-2c549fd5429a.png align="center")
        
    
    ## 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.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743090600235/b9666a5d-2ce2-4122-900d-909c8eadb31c.png align="center")
        
          
        
    2. 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
        
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743091001964/9930d48a-7094-4bd5-83b5-8733282720ce.png align="center")
    
    ## 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.
    
      
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743156111540/346e4e7e-1170-4501-a3ed-f376777748e7.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743158708830/f023fac1-7284-404a-a4f3-79f47e85ce38.jpeg align="center")
    
    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.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1743091466305/bb480d50-9250-44e5-a736-ffa2c75e983a.png align="center")

/
