How to access Azure VM (Virtual Machine)

In this azure tutorial, we will discuss How to access Azure VM (virtual machine). Apart from this, we will also discuss on the below topics:

  • Can’t connect azure virtual machine
  • How to connect the virtual machine using PowerShell
  • Azure virtual machine remote desktop can’t connect
  • Azure virtual machine RDP
  • Azure virtual machine windows 10
  • Sign in to the virtual machine in Azure using Azure Active Directory Authentication (Preview)
  • Enable Azure AD login for your VM in Azure
  • How to connect to Azure Virtual Machine from the command line
  • Different Options: Securely Connect To Your Azure Virtual Machines
  • Allowing External RDP To Your Azure VM

How to access Azure VM (Virtual Machine)

Let’s discuss how to access the Azure virtual machine (VM) which I have already created an Azure VM from the Azure portal.

How to connect and sign on to an Azure virtual machine

Follow the below steps to access the VM

Step- 1: Login to https://portal.azure.com/

Step- 2: Search for Virtual machines there.

How to access the virtual machine in azure

Step- 3: You will see the list of VM created in your Azure subscription. It will show the VM name, Type, Status, ResourceGroup, Location, etc.

How to connect the virtual machine in Azure

Step- 4: Now click on the VM name. “MyNewVM” in my case. You can able to see the details of your virtual machine like Public IP address, status, Computer name, Operating system, Size etc.

how to access azure vm

Step- 5: The next step is click on “Connect” button and then select “RDP” from the options.

How to connect the Azure virtual machine

Step- 6: Now you can able to see the IP address and port number of your VM. By default, it will populate with the correct IP and Port number of your VM but you can cross-check and choose the appropriate one in case it is wrong and then click on the “Download RDP File” button.

Connect to the Azure VM

Step- 7: You can see how the RDP file will get downloaded. The name will be “YourVMname.rdp”.”MyNewVM.RDP” got downloaded in my case.

Access to azure VM

Step- 8: Now open the downloaded RDP file. Select the Connect button from the Remote Desktop Connection window.

Error connecting to my Azure VM

Step- 9: Now enter your credentials to connect to the Azure VM.

How to connect to my Azure VM

Step- 10: Select Yes option from the below window. Now you should able to connect to your VM.

Error connecting to my Azure virtual machine

Can’t connect azure virtual machine

Some times at Step- 8, after clicking on the connect button from the Remote Desktop Connection window you might get the below error

“Remote Desktop cannot connect to the remote computer for one of the reasons “

Remote Desktop cannot connect to the remote computer for one of the reasons

To fix this we need to perform few steps.

Now go to the Overview tab and see the status of your virtual machine. You can see the status is “Stopped“. This is the reason we are getting this error while trying to connect to the VM.

connection error while connecting to Azure VM

Now to fix this, we need to start the VM. To do so click on the Start button

connection error while connecting to Azure VM 1

Now if you will see the status of the VM is changed to “Running”.

how to access azure vm

Now if you will try to connect to the virtual machine, you should be able to connect with out any issue.

How to connect Azure VM (virtual machine) using PowerShell

To connect to the virtual machine using power shell, You should make sure the Azure PowerShell module is installed for you.

You can execute the below command in your power shell, Which will lunch the RDP window directly.

Get-AzRemoteDesktopFile -ResourceGroupName "newresgroup" -Name "MyNewVM" -Launch

Here, ResourceGroupName is the Resource group name specified by you while creating the virtual machine.

Name is nothing but the virtual machine name specified by you while creating the VM.

If you want to keep the downloaded RDP file in your local path and then you want to run the RDP file to connect the VM, You can run the below command in your Power shell window.

Get-AzRemoteDesktopFile -ResourceGroupName "newresgroup" -Name "MyNewVM" -LocalPath "C:\Raj\Azure"

Here, ResourceGroupName is the Resource group name specified by you while creating the virtual machine.

Name is nothing but the virtual machine name specified by you while creating the VM.

LocalPath is the path where you want to keep the downloaded RDP file locally.

Azure virtual machine remote desktop can’t connect

There are multiple issues you might get while connecting to your virtual machine. So that it fails to connect.

You can try out multiple ways to trouble shoot the actual issue.

Reset your Remote Desktop Connection

If you can’t connect to your virtual machine, There is a chance if you are resetting your connection might help you to fix the issue.

This step will reset the RDP configuration.

Step- 1: To do this, select your Virtual machine from the Azure portal and from the left menu from Support + troubleshooting section, select the “Reset password” button

Azure virtual machine remote desktop can't connect

Step- 2: Now the below window will open, select the mode as “Reset configuration only” and then click on the “Update” button.

How to connect the virtual machine using PowerShell

Check resource health of your Azure VM

You can check the health of your VM. To do so follow the below path

Step- 1: Select your Virtual machine from the Azure portal and from the left menu from Support + troubleshooting section, select the “Resource health” button

Check resource health of your Azure VM

Step-2: After clicking on the “Resource health” button you should see the status as “Available”. This is the symbol of a healthy VM.

How to check resource health of your Azure VM

Sometimes you might see the Resource health status as unavailable like below.

Resource health Unavailable for my VM

This is because, your VM status might be “Stopped(Deallocated)” or not running. Go to the Overview tab and check. If you can see here the status is “Stopped(deallocated)“. Now to fix this click on the Start button.

How to check the status of my Azure VM

Now after clicking on the Start button, You can see the status got changed to “Running”.

How can i start my azure VM

Now after clicking on the “Resource health” button you should see the status as “Available”.

Azure virtual machine remote desktop can't connect

Reset password of your Azure VM

You can reset your Azure VM password in case you forget it or showing wrong credentials .

To reset your password of your VM in Azure, follow the below steps.

Step-1: Select your Virtual machine from the Azure portal and from the left menu from Support + troubleshooting section, select the “Reset password” button

How to reset password of your Azure VM

Step-2: Select the Mode as “Reset password“. Enter your Username, Password, and Confirm password and then click on the Update button.

How to reset password of your Azure VM

Redeploy Azure VM

In case you are facing any network issue while connecting your virtual machine, you can redeploy your VM in Azure.

To do this, follow the below steps

Step-1: Select your Virtual machine from the Azure portal and from the left menu from Support + troubleshooting section, select the “Redeploy” button

How to redeploy your Azure VM

Step- 2:You will see the successful message once you click on Redeploy button.

How to redeploy your Azure VM

Restart Azure VM

To fix any small small issues inside your VM, you can simply restart your virtual machine.

You can restart your virtual machine by following the below steps

Step- 1: Select the Overview tab and click on Restart button.

How to restart the Azure VM

Step-2: Now select “Yes”.

Restart the Azure VM

Step- 3:You will get a successful message like below.

How can I restart my Azure VM

Azure virtual machine RDP

We can connect to the azure windows virtual machine by using Remote Desktop Protocol(RDP) from the Azure Portal as well as from your local PC.

Connecting to Azure VM using RDP from Azure Portal

You can follow the below steps to connect your VM through RDP from Azure portal.

Step- 1: Select your virtual machine in azure portal, Go to the Overview tab and click on “Connect” button. Then click on RDP option from there.

Azure virtual machine RDP

Step- 2: Now you can able to see the IP address and port number of your VM. By default, it will populate with the correct IP and Port number of your VM but you can cross-check and choose the appropriate one in case it is wrong and then click on the “Download RDP File” button.

How to download the RDP file

Step-3: Now your RDP file will get downloaded. You can open that and click on Connect button.

connect your VM using RDP option

Step- 4: Once you click on Connect button, now enter your credentials to connect to the Azure VM.

How can i connect to my Azure virtual machine.

Step- 5: Select Yes option from the below window. Now you should able to connect to your VM.

how do i connect to my Azure VM

Connecting to Azure VM using RDP from local PC

You can follow the below steps to connect your VM through RDP from your local system.

Step-1: Search for “mstsc” in your local machine you will find “Remote Desktop Connection” app. click on that.

How to connect your vm using RDP option

Step- 2: Now in the below window, enter the public IP of your virtual machine and then click on the “Connect” button.

How to connect to your Azure virtual machine

Step- 3: Enter your credentials to login to the virtual machine in the windows security window. Click on OK.

Connect to the Azure virtual machine using RDP

Step-4: Select Yes option from the below window. Now you should able to connect to your virtual machine (VM).

how do i connect to my Azure VM

Azure virtual machine Windows 10

You can access the azure virtual machine from widows 10.

First you need to login to the Azure portal. From the Azure portal you connect to the virtual machine and check if the Remote desktop connection is enabled in the virtual machine.

Search for settings then click on System. Click on the “Remote Desktop” option. If you can see Enable Remote Desktop option is off now for me. So need to make it On first.

Enable remote desktop option in azure virtual machine

Now change the Enable Remote Desktop option to on and click on “Confirm” button.

how to enable remote desktop option in azure virtual machine

If you can see the Enable Remote Desktop option is ON for you then no need to enable it again you can ignore the above two steps. By default the Enable Remote Desktop option is ON for newly created virtual machine in Azure.

Now to connect the virtual machine from Windows 10 machine locally via RDP you can follow the below steps.

Step- 1: First if you don’t know the public IP of your virtual machine login to the Azure portal and search for your virtual machine and click on that and go to the Overview tab.

Here you can see the public ip address of my virtual machine is “13.64.175.88”.

How to get the public ip address of your virtual machine in Azure

Step-2: Now search for “mstsc” in your local machine you will find “Remote Desktop Connection” app. click on that.

How to get the public ip address of your virtual machine in Azure

Step-3: Now in the below window, enter the public IP of your virtual machine and then click on the “Connect” button.

How to connect to the Azure VM from windows 10 machine

Step- 4: Enter your credentials to login to the virtual machine.

How to connect to the Azure virtual machine from windows 10 machine

Step- 5: Select Yes option from the below window. Now you should able to connect to your VM in Azure.

how do i connect to my Azure VM

This is how we can connect the windows Azure virtual machine from windows 10 machine locally.

Sign in to the virtual machine in Azure using Azure Active Directory Authentication (Preview)

Well, here is good news, you can connect to your Windows Azure Virtual machine using the Azure Active Directory Authentication (Preview).

Prerequisites

As a prerequisite, you need to note down that the Azure virtual machine must be running on Windows Server 2019 Datacenter edition or Windows 10 1809 and later.

Benefits

Below are a few key benefits of using the Azure Active Directory Authentication (Preview) to sign in to the Virtual Machine.

  1. It helps you to centrally control and enforce policies for your Azure Virtual Machine.
  2. You can utilize the Azure AD credentials that you have.
  3. Since you are using your Azure AD credentials, no need to maintain the local administrator accounts.
  4. You can utilize the Azure role-based access control to access your Azure VMs.
  5. With the Azure AD authentication, you can also utilize the Multi-factor authentication and Sign-in risk check for additional security.

Enable Azure AD login for your VM in Azure

You can enable the Azure AD login for your Windows VM in Azure using the following methods.

  1. Using the Azure portal while creating a Windows VM
  2. Using the Azure Cloud Shell while creating a Virtual Machine or in case of an existing Windows VM

Using the Azure portal while creating a Windows VM

You can follow the below steps to enable the Azure AD authentication option while creating a Virtual machine.

  1. Log in to the Azure Portal (https://portal.azure.com/)
  2. Once, you have logged in to the Azure Portal, search for the Virtual machines, and then click on the search result Virtual machines.
  3. On the virtual machines page, click on the + Add dropdown and then click on the + Virtual Machine option to create a virtual machine.
  4. On the Basic tab, Fill out all the mandatory fields and Make sure to choose the image option as Windows Server 2019 Datacenter.

Or, for the same option, you can follow the below steps

Once you have logged in to the Azure Portal, click on the + Create a resource from the left navigation.

Search for windows server and click on the search result, windows server, and then select the Windows Server 2019 Datacenter option from the Select a software plan dropdown and click on the Create button.

5. On the “Management” tab, enable the option to log in with AAD credentials (Preview) under the Azure Active Directory select the option from Off to On

6. Set the System assigned managed identity option to ON which is present under Identity section.

7. Provide the value for all the mandatory option and then click on the Review + Create button.

Note: You might not see the “log in with ad credentials (preview) ” option, since it is not in production till now and it’s in Preview. You will see that in the future.

Using the Azure Cloud Shell while creating a Virtual Machine

You can also enable the Azure AD login for your Windows VM in Azure using the below Azure CLI script.

az group create --name DemoResourceGroup --location southcentralus

az vm create \
    --resource-group DemoResourceGroup \
    --name tsinfoVM \
    --image Win2019Datacenter \
    --assign-identity \
    --admin-username testing \
    --admin-password testing 123

How to connect to Azure Virtual Machine from the command line

You can also able to connect your Azure Linux VM from Azure CLI or from the command prompt using the SSH key. The cmdlet to connect the Azure Linux VM is as below

$ ssh -i <private key path> [email protected]<Public IP>

Different Options: Securely Connect To Your Azure Virtual Machines

It’s really very important to connect to your Azure Virtual Machine very securely. Security matters a lot while accessing your Azure Virtual Machines. So luckily, there are multiple options that can help you to access your Azure VMs securely without any issue. Let’s discuss all the options here.

Just-in-time VM access

Just-in-time VM access is an excellent option to securely connect your Azure VM. An excellent thing is that think of a scenario when you only have the port open when you need it that helps you to reduce the vulnerability. For the sake of security, it helps you to open the port when you actually need it and immediately locks the ports and once your works are over, it immediately makes sure to close the port.

You can easily enable and configure the Just-in-time VM access in two ways. Either you can do the configuration from the Azure security center or you can configure it programmatically on a VM directly.

Advantage: It provides you high security and reduces the risk of any malicious attack as it opens the port only when you need it and immediately closes it once your work is done.

Disadvantage: One problem is that you still have to open the port 3389 to public internet.

RDP using a Private IP address with Site to Site VPN

You can also able to connect to the Azure VM using the Private IP address across site to site VPN. This approach helps you to communicate with the Azure VM and provides proper protection against port scanning and reduces the malicious attacks by connecting with a VPN gateway and The important point is, you can use the Private IP address and avoiding the Public internet.

If you don’t need the public IP address then you can remove that and the RDP port 3389 will be closed if you are not using it.

Using a Jumphost solution

You can use the jumphost solution that will reduce the risk of exposing all your Virtual machines to the public internet. This creates a single Virtual machine which is known as jumphost and From this box, you can connect to your other Virtual machines in your Network.

It’s quite easy to deploy the jumphost and provides with high security on your Azure VM infrastructure.

Using Azure Bastion 

Azure Bastion is an excellent solution that helps you to connect to your Virtual machine without using the Public IP address or VPN connectivity. It normally uses the browser-based HTTP connectivity and since it is not using the Public IP address so it is really secure to access the Azure Virtual machine using the Azure Bastion.

It is an excellent service that is very newly introduced and helps you with the opportunity to connect to your VM in the Azure Portal over the SSL. It acts as a jump server as-a-service where no need for a Public IP address. You don’t need any additional software to connect to the Azure Virtual machine.

Advantage: One biggest advantage is that we don’t need the Public IP to connect to the Azure VM So it’s more secure as compare to the other methods.

Disadvantage: It is quite difficult to find and is not available for all the regions and available for limited regions.

Allowing External RDP To Your Azure VM

While working with the Azure Virtual machine, there are certain scenarios where, you need to allow your Azure virtual machine to connect from externally.

There are multiple ways to set the external RDP to your Azure Virtual Machine.

While creating the New Azure VM select the port you want to allow

You can select the ports you want to allow while creating the new Azure Virtual machine.

On the Create a virtual machine page, you need to select the “Allow selected ports” option and then you need to select the ports that you want to allow your Azure VM to connect.

Allowing external RDP to your Azure VM

Edit the Network Security Group for an existing VM

Once you have created the Azure virtual machine, you can add an Inbound Port Rule to allow the external access.

Once you will login to the Azure Portal, you can navigate to the Specific Azure VM and then under networking section, click on the “Add Inbound Port Rule”. Then fill out the below details

  • Source: Any
  • Source Port ranges: *
  • Destination: Any
  • Destination Port Ranges: 3389
  • Action: Allow

The other options should be based on your requirement.

Create a new Security Group and use it while creating a new VM

You can also create a new Network security Group and select that one while creating a new Azure Virtual machine.

Once, you have created your Network Security Group, While creating the Azure Virtual machine, on the Create a Virtual machine page, on the Networking tab, select “Advanced” under “NIC network security group” and select the newly created security group.

How to Allow external RDP to your Azure VM

You may like following Azure tutorials:

Conclusion

In this Azure tutorial, We discussed

  • How to access Azure VM (Virtual Machine)
  • How to connect to Azure windows VM
  • Quickly Connect to Windows VMs with RDP
  • Securely connect to your Azure Virtual Machines
  • Can’t connect azure virtual machine
  • How to connect Azure VM (virtual machine) using PowerShell
  • Azure virtual machine remote desktop can’t connect
  • Reset your Remote Desktop Connection
  • Check resource health of your Azure VM
  • Reset password of your Azure VM
  • Redeploy Azure VM
  • Restart Azure VM
  • Azure virtual machine RDP
  • Connecting to Azure VM using RDP from Azure Portal
  • Connecting to Azure VM using RDP from local PC
  • Azure virtual machine Windows 10
  • How to connect to Azure Virtual Machine from the command line
  • Different Options: Securely Connect To Your Azure Virtual Machines
  • Allowing External RDP To Your Azure VM