Creating an Azure virtual machine using command-line interface (CLI)
Tags: cli, azure, cloud, cloudcomputing
Published: 2023-05-13 22:16:21

Welcome, tech enthusiasts! In this blog post, we will be looking at how to create an Azure virtual machine using the command line. This blog is perfect for you if you are new to Azure or are just beginning to explore the exciting possibilities of cloud computing.

But first, let's take a look back at some of our prior blog posts. We explained how to create a virtual machine using the Azure [portal](https://dev.to/henriettatkr/creating-a-virtual-machine-in-azure-a-step-by-step-guide-for-beginners-387f), [PowerShell](https://dev.to/henriettatkr/a-step-by-step-guide-to-easily-creating-azure-virtual-machines-with-powershell-1kib), [an ARM Template, and Azure Quick Start](https://dev.to/henriettatkr/create-a-virtual-machine-in-less-than-a-minute-with-arm-template-and-azure-quick-start-1bbb) in earlier posts. We hope you found those blogs helpful and educational. Today, we'll expand on that understanding by teaching you to the power of the command line.

Azure command-line interface (**CLI**) is a command-line tool that can be used to manage Azure resources from any operating system. 

To begin, log in to the Azure Portal using this [link](https://azure.microsoft.com/en-gb/free/) 

Once you are logged in, you should see a search bar at the top of the page. To the right of the search bar, there should be an icon that looks like a >_ symbol as highlighted in the image below. This is the Cloud Shell icon.
Click on the Cloud Shell icon to open the Cloud Shell window.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hgvv1merwskh4wdozu4y.png)

Select the Bash option to open the command line environment within the Cloud Shell.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jfd6xb6xgv5oalglae5g.png)

**Step 1: Create a Resource Group**
To create a resource group, you can use the following command:

```
az group create --name myCoolg --location EastUs
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o0je9q7sv8xl3g4htno1.png)

Replace '**_myCoolRg_**' with the name of your resource group and '**_EastUS_**' with the location of your choice.

**_Step 2: Create a Virtual Machine_**
To create a virtual machine, you need to use the az vm create command. The command takes a few parameters that define the configuration of the virtual machine. Here's an example of how to create a virtual machine:

```
az vm create - -resource-group myCoolRg --name myVMcli --image UbuntuLTS --generate-ssh-keys
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o0bilyf1dr2n0mxx4zeb.png)

**Step 3: Verify the Virtual Machine Creation**
After you have created the virtual machine, you can verify that it has been created successfully and running 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xwzhyrn4f9iyovxh4ad.png)

Creating an Azure virtual machine using the CLI is a simple process that involves creating a resource group, defining the configuration of the virtual machine, and verifying the creation. By following the steps outlined above, you can create an Azure virtual machine quickly and easily.