Step-by-Step Guide to Create a Linux Virtual Machine in Azure

Step-by-Step Guide to Create a Linux Virtual Machine in Azure

Creating a virtual machine (VM) on Azure is a straightforward process, and it’s a powerful way to access on-demand computing resources. In this guide, we’ll walk you through the process of creating a Linux virtual machine on Microsoft Azure, step by step.


Step 1: Sign In to Azure Portal

  1. Navigate to the Azure Portal.

  2. Login with your Microsoft account. If you don’t have an account, you can create one for free.


Step 2: Create a New Resource

  1. Once logged in, click on the "Create a resource" button in the left-hand menu.

  2. In the search bar, type "Virtual Machine" and select "Virtual Machine" from the results.

  3. Click on the "Create" button to start configuring your VM.


Step 3: Configure the Basics

On the Basics tab, you’ll configure the primary settings of your Linux VM.

  1. Subscription: Select the Azure subscription you want to use.

  2. Resource Group: Either select an existing resource group or create a new one by clicking "Create new" and giving it a name.

  3. Virtual Machine Name: Enter a unique name for your VM (e.g., myLinuxVM).

  4. Region: Choose the Azure region closest to you for optimal performance and lower latency (e.g. (Europe) UK Soutth).

  5. Availabilty zone: Select the availability zones for your virtual machine. For high availabilty, more than one zone can be selected. Use the dropdown to see all the zones.

  6. Image: Click ”See all images” and select your desired Linux distribution (e.g., Ubuntu Server 22.04 LTS).

  7. Size: Click "See all sizes" and select a VM size based on your performance needs and budget. Remember to click the ”Select” button after choosing a VM size.

  8. Authentication Type: Choose between SSH public key (recommended for security) or Password.

    • If you select SSH public key, provide your public key, or generate a new one.

    • If you select Password, set a strong username and password.

    • Take note of the Username as this will be used later for remote connection to the VM.

  9. Inbound Port Rules: Select Allow selected ports and choose SSH (22) to enable remote access. Use the dropdown to see all available ports.

Click Next: Disks.


Step 4: Configure the Disk

  1. OS Disk Type: Choose the disk type (SSD for performance or HDD for cost savings).

  2. Optionally, add a data disk by clicking "Create and attach a new disk" for additional storage.

Click Next: Networking.


Step 5: Configure Networking

  1. Virtual Network (VNet): Use the default VNet or create a new one for your VM.

  2. Subnet: Select a subnet for the VM.

  3. Public IP: Leave the default to automatically assign a public IP.

  4. NIC Network Security Group: Choose Basic and allow SSH (22) if not already selected.

Click Next: Management.


Step 6: Configure Management Options

  1. Auto-Shutdown: Configure auto-shutdown if needed to save costs during inactive periods.

  2. Backup: Enable Azure Backup for disaster recovery if required.

Click Next: Monitoring.


Step 7: Configure Monitoring Options

Decide whether to enable monitoring options like Boot diagnostics and guest OS diagnostics.

Click Next: Advanced

Step 8: Configure Advanced Options (Optional)

  1. Add scripts, configurations, or extensions if required for custom initialization.

  2. Skip this step if you don’t need any additional setup.

Click Next: Tags.


Step 9: Add Tags

Tags are optional but useful for organizing and tracking resources. Add key-value pairs to label your VM (e.g., Environment: Development).

Click Next: Review + Create.


Step 10: Review and Create

  1. Review all the configuration details of your VM.

  2. Click "Create" to start the deployment process. This can take a few minutes.

  3. When prompted, click ”Download private key and create resource” to download private key pair. This will only show up if you have selected SSH as the Authentication type in Step 3 and you have chosen to Generate new key pair


Step 11: Connect to Your Linux VM

  1. Once your VM is deployed, you’ll receive a notification. Click ”Go to resource” to navigate to the virtual machine interface in the Azure Portal

  2. From the ”Connect” dropdown tab, click Connect. Make a note of the Public IP address and the Admin username. These will be used, with the downloaded private key pair, to SSH into the virtual machine from our local machine.

  3. Copy the SSH command provided and paste it into your terminal:

     ssh -i </path/to/downloaded/private/key.pem> <username>@<ip_address>
    
  4. We are using Windows PowerShell terminal as shown below. When promted to authenticate, type yes.

Step 12: Start Using Your VM

Congratulations! You now have a fully functional Linux virtual machine running on Azure. You can use it to host applications, run scripts, or practice Linux commands.


Tips for Managing Your Linux VM

  • Security: Always keep your VM secure by regularly updating the OS and restricting inbound traffic.

  • Cost Optimization: Shut down your VM when not in use to save costs.

  • Scaling: If you need more resources, Azure allows you to resize your VM as needed.


By following this guide, you’ve successfully created a Linux virtual machine in Azure. For more insights and tutorials, keep following my blog! 🚀