Creating Your First Virtual Machine on Azure with Azure CLI
Introduction:
Do you want to harness the power of cloud computing with Microsoft Azure? The Azure CLI (Command-Line Interface) is your key to managing Azure resources efficiently from the comfort of your terminal. This guide will equip you with the knowledge to install the Azure CLI on your Windows, macOS, or Ubuntu machine, log in securely, and create your first virtual machine (VM) with ease.
Objective:
This blog post aims to empower you with the following:
- Installing Azure CLI: Learn the straightforward steps to install the Azure CLI on your preferred operating system.
- Logging In: Understand the secure login process to authenticate with your Azure account.
- Creating a Virtual Machine: Discover the essential commands to create a basic VM on your Azure account.
By following these steps, you’ll gain hands-on experience and be well on your way to exploring the vast capabilities of Azure in a practical way.
Setting up Azure CLI
Windows
- Download and Install: Go to the Azure CLI installation page (https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows) and download the MSI installer. Run the installer and follow the prompts.
- Verify Installation: Open a new Command Prompt window and run
az --version
to check if Azure CLI was installed correctly.
Mac OS
- Install with Home brew: Open Terminal and run:
brew update && brew install azure-cli
Verify Installation: Run az --version
to ensure Azure CLI is installed properly.
Linux (Ubuntu)
- Install with one command: Open a terminal and run:
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
Verify Installation: Check the installation by running az --version
.
Logging into Azure
- Login: Run
az login
in your terminal or command prompt. This command will open a web page where you can log in using your Azure account credentials. - List Subscriptions: To list all your available subscriptions, use
az account list --output table
. If you have multiple subscriptions, set the one you intend to use withaz account set --subscription "SubscriptionName"
.
Creating a VM with Azure CLI
- Create a Resource Group: If you don’t already have a resource group, create one.
az group create --name az-900 --location eastus
Create a Virtual Machine: Now, create your VM.
az vm create --name siddhant-server --resource-group az-900 --image Canonical:0001-com-ubuntu-server-jammy:22_04-lts:latest --admin-username your_admin_username --admin-password your_password --public-ip-address-dns-name siddhant-server
az vm open-port --name siddhant-server --resource-group az-900 --port 80 --priority 900
az vm open-port --name siddhant-server --resource-group az-900 --port 443 --priority 991
- Adjust
--image
for different OS options, and--admin-username
as needed. - Access the VM: After the VM is created, you can SSH into it using its public IP address.
ssh azureuser@<PublicIPAddress>
- Manage VM: Learn more about managing your VM, such as starting, stopping, and deleting, by visiting the Azure CLI documentation on VM management (https://docs.microsoft.com/en-us/cli/azure/vm).
- Delete the Resource
az group delete --name az-900 --yes --no-wait
Useful Links
- Azure CLI Documentation: https://docs.microsoft.com/en-us/cli/azure/
- Azure CLI VM Management: https://docs.microsoft.com/en-us/cli/azure/vm
- Azure CLI Installation Guide: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli
Make sure to replace placeholders with your actual values where necessary, and adjust commands based on your specific requirements or Azure CLI updates. This guide provides a general outline, but the Azure documentation will have the most current and detailed information