DEV Community

JICDev
JICDev

Posted on

How to Create a Linux Virtual Machine in Azure Portal

Microsoft Azure makes it easy to deploy virtual machines (VMs) that run Linux. Whether you want to test an application, host a service, or learn Linux administration, setting up a VM in Azure is a great way to get started.

This guide will walk you through creating a Linux VM on Azure Portal step by step.

Step 1: Sign in to Azure Portal

  1. Go to https://portal.azure.com.
  2. Log in with your Azure account credentials.
  3. You’ll land on the Azure Home dashboard.

There after your interface should look like the image below. Now you can click on Virtual Machine (VM). Mind you, you can also use the search bar for this purpose.


Step 2: Click on Create

Step 3: Configure Basics - This is where you fill in all the modalities of the virtual machine. You would select as below:

  • Subscription → Choose your subscription.

  • Resource Group → Select an existing one or click Create new Click here to learn how to do so. After creating your resource, then you select the resource you created.

  • Virtual machine name → Example: TestMachine.

  • Region → Choose the closest region to you or your users (e.g., East US, West Europe). NB: This can have an impact on the costing.

  • Availability options → Leave as default for a simple setup. However, you choose zone if you what your Vm to be deployed to different zones. Mind you, the more the zones, the higher the pricing. For this test, kindly choose "No infrastructure redundancy required"

Select your image* Here you would see various operating system available. Since we are creating for a Linux VM we would use the Ubuntu Server 24.04 LTS as in the image below:


  • Size → Pick a VM size (e.g., Standard_B1s for testing "if you are using a free account" But if you are using a pay as you go account you can use any other that fits your needs".

Step 4: Administrator Account

Set up the login details:

  • Authentication type → Choose SSH public key (recommended) or Password.
  • Username → Enter a Linux username (e.g., Testuser1).
  • SSH public key source

    • If you already have a key, paste the public key.
    • Or generate a new one inside the portal.

🔹 Step 5: Inbound Port Rules

To connect via SSH, you need to allow port 22.

  • Public inbound ports → Select Allow selected ports.
  • Select inbound ports → Check SSH (22).

Security Note: For production, it’s better to allow SSH only from your IP.

🔹 Step 7: Review + Create

  1. Click Review + Create.
  2. Azure will validate your configuration.
  3. If validation passes, click Create.

Deployment will take a few minutes.

At this point you would be prompted to download the .pem file which would enable you to possible deploy the Linux VM (if you used SSH as your login type) Download it for later as seen below:

It should like below:

🔹 Step 8: Connect to Your Linux VM

Once the VM is deployed: Clickk on "Go to resource"

Go to Virtual machines in the left menu.

Select your new VM and click on Connect:

Copy the SSH command provided, e.g.:

 ssh -i ~/.ssh/id_rsa azureuser@<Public-IP> 
Enter fullscreen mode Exit fullscreen mode

  1. Run the command from your Windows PowerShell or a Linux terminal. So open you PowerShell if you use a windows computer like me. i.e see image below any one will do.

Apply the following prompts: Note if you logged in using SSH: you need to navigate to the file.pem location to run the your VM.

Once in, do the following paste the copied SSH command

 ssh -i ~/.ssh/id_rsa azureuser@<Public-IP> 
Enter fullscreen mode Exit fullscreen mode

If you did everything right!!! You will be required to authenticate, type in yes. There you go!!!

You can use the following command to confirm you are in the right VM i.e "pwd" "whoami"

Now free to logout, by typing "Logout" command.

If you are using a "pay as you go" Azure account, always remember to disconnect/stop the machine from running in the background to avoid being heavily charged. You can do so y going to your virtual machine and click stop or you delete entirely.

You’re now connected to your Linux VM!


Conclusion

Creating a Linux VM on Azure is straightforward: From here, you can start installing packages, hosting services, or experimenting with Linux commands.

After this you can now decide to start installing packages, hosting services, add data disks (click here) or experimenting with Linux commands.

Top comments (0)