Creating And Managing Azure Linux Virtual Machine Via The Command Line Interface

WHAT IS THE COMMAND LINE INTERFACE (CLI)?:
A command-line interface (CLI) is a text-based user interface (UI) used to run programs, manage computer files and interact with the computer. The commands are typically composed of specific keywords, options, and parameters that control various functions and tasks of the program or system
In Microsoft Azure, there is a CLI tool that enables users to interact with their Azure account via a CLI interface, this tool is called the Azure CLI. For Azure-specific syntax, you need to install the Azure CLI and log into your Azure account via the Azure CLI.
STEP 1: Installing the Azure CLI
Go to https://learn.microsoft.com/en-us/cli/azure/install-azure-cli. Select your operating system accordingly and follow the steps.
Kindly note that installation is only required once. If you already have it installed you can skip this process and continue to Step 2

Step 2: Log into your Azure account via the CLI
Open any CLI application of your choice. I am using a Windows system and I will make use of the traditional CMD windows that came with Windows. On your Windows search bar type CDM.
To confirm if Azure CLI is installed. Type az version on your CMD

Log in to your Azure account by typing az login

From here a browser will open requesting you to select Azure account to log into
*Select the account
You will receive the confirmation below

At this stage return to your CMD and tap enter

Step 3: Create your resource group
Create a new resource group where your VM will be deployed with the following command.
az group create --name <ResourceGroup Name> -- location <input the Azure location you want your resource to be> and press enter.
For this example, we will have our ResourceGroup name - testRG and Location - UKSouth

Weldone the resource group has been successfully created.

Step 4: Create a Linux VM in the testRG resource group
To create the VM via the CLI use the syntax-
az vm create -- resource-group <resource group name> -- name <name of VM> --image <image name> -- admin-username <username> -- admin-password <password>
Take note
-- resource-group: Here we add the Resource group we created earlier on {testRG}
-- name: Provide a name for your VM. I will call mine azurelinux
-- image: Choose the operating system you want to use I will be using the UbuntuLTS.
--admin-username: This is the admin username for the VM- I will call mine azurelinux
--admin-password: Set the password for the VM, you have to remember this to be able to log into the VM. Remember your password must meet the requirements for VM password as stipulated by Azure

Now your virtual machine is created. We need to log into the machine. You can confirm it via the Azure portal, but since we are working with the CLI, let us log in using it.
Kindly note that our VM username is azureuser and password is noted, we can use the command as below:

With the ssh command I have succesfully logged into the CLI of my Ubutu VM.
MANAGING MY AZURE VIRTUAL MACHINE
It is pertinent to know some syntax to use in managing your VM via the CLI. I will be sharing some of the basic ones with you.
Current state of our VM is running as shown below from the Azure portal

To stop and start the VM
STOP: az vm stop --resource-group <name> --name <VM name>
az vm stop --testRG --azurelinux


START- az vm start--resource-group <name> --name <VM name>
az vm start--testRG --azurelinux


To list IP addresses assigned to the VM
az vm list-ip-addresses --resource-group <name> --name <VM name>
az vm list-ip-addresses --resource-group testRG --name azurelinux

There are more commands that can be used to interact with your VM via the CLI.
I hope this write-up has been educative. Kindly like and share.
Femi Moses

