In this guide, we'll walk through the process of creating a Virtual Machine (VM) in Azure and connecting to it using three different methods:
Azure Portal (UI-based)
Azure CLI (Command Line Interface)
PowerShell (Azure PowerShell Module)
We'll also cover how to connect to the VM via RDP (for Windows) or SSH (for Linux).
Create and Connect to a VM Using the Azure Portal (UI)
Step 1: Create the Virtual Machine
Sign in to the Azure Portal:
Go to and sign in with your credentials.Create a Virtual Machine:
In the left sidebar, click on "Create a resource".
Search for "Virtual Machine" and select it.
Click "Create".
Configure the VM:
Subscription: Select your subscription.
Resource Group: Create a new or select an existing one.
VM Name: Enter a name (e.g.,
MyVM).Region: Select the region (e.g.,
East US).Image: Select the operating system image (e.g.,
Windows Server 2022orUbuntu 20.04).Size: Select a size (e.g., Standard B1s for a small VM).
Authentication:
For Windows, use a Username and Password.
For Linux, use SSH public key or Password.
Inbound Port Rules: Select Allow selected ports and choose RDP (3389) for Windows or SSH (22) for Linux.
Networking:
Configure the Virtual Network (VNet), Subnet, and Public IP Address.
Ensure a Public IP Address is selected for remote access.
Disks: Select your preferred disk type (e.g., Standard SSD).
Review & Create: Review your settings and click "Create" to deploy the VM.
Step 2: Connect to the Virtual Machine
Navigate to the VM: Once the VM is deployed, go to Virtual Machines in the Azure portal and select the VM you just created.
Get the Public IP Address: On the VM overview page, note down the Public IP Address.
For Windows VM (RDP):
Open Remote Desktop Connection on your local machine.
Enter the Public IP address of the VM.
Enter the username and password when prompted.
For Linux VM (SSH):
Open a terminal (Linux/macOS) or an SSH client (Windows).
Use the command:
xxxxxxxxxx11ssh username@<public_ip_address>If you're using an SSH private key, specify it using:
xxxxxxxxxx11ssh -i /path/to/your/private_key username@<public_ip_address>
Create and Connect to a VM Using Azure CLI
Step 1: Install Azure CLI
If you don’t have Azure CLI installed, you can install it by following the instructions on Azure CLI installation.
Step 2: Log in to Azure CLI
Run the following command to log in:
xxxxxxxxxx11az loginThis will open a browser for authentication.
Once you’re authenticated, you can use Azure CLI commands.
Step 3: Create the Virtual Machine
Use the following command to create a new VM:
For Windows VM:
xxxxxxxxxx81az vm create \2--resource-group MyResourceGroup \3--name MyVM \4--image Win2019Datacenter \5--size Standard_B1s \6--admin-username myadmin \7--admin-password 'YourPassword123!' \8--public-ip-sku StandardFor Linux VM:
xxxxxxxxxx81az vm create \2--resource-group MyResourceGroup \3--name MyLinuxVM \4--image UbuntuLTS \5--size Standard_B1s \6--admin-username myadmin \7--generate-ssh-keys \8--public-ip-sku StandardFor Linux: This command generates an SSH key pair for authentication.
Step 4: Get the Public IP Address of the VM
To retrieve the public IP address, use:
xxxxxxxxxx41az vm list-ip-addresses \2--resource-group MyResourceGroup \3--name MyVM \4--output tableStep 5: Connect to the Virtual Machine
For Windows (RDP):
Use the following command to get the RDP file:
xxxxxxxxxx41az vm open-port \2--port 3389 \3--resource-group MyResourceGroup \4--name MyVMThen connect using Remote Desktop Connection.
For Linux (SSH):
If using SSH, connect with the following command:
xxxxxxxxxx11ssh myadmin@<public_ip_address>Use the SSH key if you generated one during creation, or provide the password for authentication.
Create and Connect to a VM Using Azure PowerShell
Step 1: Install Azure PowerShell
If you don't have Azure PowerShell installed, follow the installation guide here.
Step 2: Log in to Azure PowerShell
Run the following command to log in to your Azure account:
xxxxxxxxxx11Connect-AzAccountStep 3: Create the Virtual Machine
For Windows VM:
xxxxxxxxxx71New-AzVM `2-ResourceGroupName MyResourceGroup `3-Location EastUS -VMName MyVM `4-ImageName Win2019Datacenter `5-Size Standard_B1s `6-Credential (Get-Credential) `7-PublicIpAddressName MyVMIPFor Linux VM:
x1$sshKey = New-Object `2-TypeName System.String `3-ArgumentList "path-to-your-ssh-key.pub"4
5New-AzVM `6-ResourceGroupName MyResourceGroup `7-Location EastUS `8-VMName MyLinuxVM `9-ImageName UbuntuLTS `10-Size Standard_B1s `11-Credential (Get-Credential) `12-PublicIpAddressName MyLinuxVMIP `13-SSHKeyValue $sshKeyStep 4: Get the Public IP Address of the VM
xxxxxxxxxx51$vm = Get-AzVM `2-ResourceGroupName MyResourceGroup `3-Name MyVM4
5$vm.PublicIpAddressStep 5: Connect to the Virtual Machine
For Windows (RDP): Use the Remote Desktop app and connect using the Public IP address and credentials.
For Linux (SSH): Open a PowerShell terminal and run:
xxxxxxxxxx11ssh myadmin@<public_ip_address>Summary
This guide showed how to create and connect to a Virtual Machine in Azure using three different methods:
Azure Portal: A UI-based approach for those who prefer graphical interfaces.
Azure CLI: Command-line interface for managing resources, especially suited for automation and scripting.
Azure PowerShell: Ideal for those familiar with PowerShell or working in environments where PowerShell is the standard.
Each method provides flexibility for managing and connecting to your Azure VM, whether you’re using RDP for Windows or SSH for Linux.




















Leave a Reply