# A Guide to Creating Virtual Machine Using Azure CLI

[Azure documentation](https://learn.microsoft.com/en-us/cli/azure/what-is-azure-cli) defined Azure Command Line Interface (CLI) as a cross-platform command-line tool to connect to Azure and execute administrative commands on Azure resources. It works on different operating systems, like Windows, macOS, and Linux.

With Azure CLI, you can swiftly connect to Azure and perform administrative tasks on your Azure resources. You can create any resources such as virtual machines and storage accounts. It offers flexibility and efficiency by allowing you to execute commands directly from your computer's command-line interface, without the need for a graphical user interface.

**PREREQUISITE**

Before you can use the Azure CLI, you will need to Download and install Azure CLI on your computer by following the instructions provided by Microsoft [here](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli)

Now that you've installed Azure CLI, open your command prompt or Windows Powershell to get started.

**Login to Your Azure Account**

a) To login to your Azure account, type the command **az login** and press the Enter button on your desktop

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686279843235/bff0ee2c-bed1-4d36-9868-91a4a00f827e.png align="center")

b) You will be redirected to a web browser to sign in to your account.

c) Click on your account

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686279882659/d014f1e1-7bd1-49fb-b001-f754d5e77129.png align="center")

d) You will get the below notification, close the browser page and go back to the terminal.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686279916542/2cc22836-1688-464a-90a5-4092980b10a5.png align="center")

e)Welcome!! you are logged in. The command below shows your subscription and your account

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686279981313/d2bf38bd-a620-4ef5-91a8-079cc80ea2eb.png align="center")

**Create Your Resource Group**

a) The next step is to create your resource group that will accommodate your virtual machine and its dependents.

b) Input the command ;

**az group create --name** (name your resource) **--location** (input the location you want your resource to be).

c) Ensure to leave a space after each word.

d) Once you've inputted the command, Press enter.

e) Your resource group has been successfully created.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686279770616/f55e80b5-6fc5-4ac8-b623-a889a8530f0d.png align="center")

**Create Your Virtual Machine**

a)The next step is to create your virtual machine.

b) Input the command;

**az vm create --resource-group (input your resource group name) --name (name your virtual machine) --image (the name of the image you wish to use) --admin-user (the admin name) --generate-ssh-key**

c) Once you press enter, your virtual machine will start running as shown below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686279715386/c74b2a94-aff1-4d21-8dba-1f136aa5a854.png align="center")

d) When you go to your Azure portal, you can see the virtual machine created using Azure CLI.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686279672435/0cffe329-0aef-4bad-be38-e53abe5cba6f.png align="center")

I hope this helped you understand the flexibility and ease of creating resources in Azure CLI. Thank you.
