How to connect to Azure VM

This Azure tutorial will discuss different ways to connect to Azure VM.

How to connect to Azure VM

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

Follow the below steps to access the VM

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

2. Search for Virtual machines there.

How to access the virtual machine in azure

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

how to access azure virtual machine

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

how to access azure vm

5. The next step is to click the “Connect” button and select “RDP” from the options.

connect to azure vm

6. Now, you can 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 connect azure vm

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

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

how to view virtual machines in azure

9. Now, enter your credentials to connect to the Azure VM.

how to connect to azure virtual machine

10. Select the Yes option from the below window. Now, you should be able to connect to your VM.

Error connecting to my Azure virtual machine

Sometimes at Step 8, after clicking on the connect button from the Remote Desktop Connection window, you might get the error “Remote desktop cannot connect to the remote computer“. You can fix the error by following the same link. After fixing this issue, you should be able to connect without any issues.

How to connect Azure VM (virtual machine) using PowerShell

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

You can execute the below command in your power shell, Which will launch 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.

The 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 run the RDP file to connect the VM, You can run the below command in your PowerShell 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.

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

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

Connect Azure VM using 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.

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

Connect Azure VM using RDP from Azure Portal

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

Azure virtual machine RDP

2. Now you can 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 login to azure vm

3. Now, your RDP file will get downloaded. You can open that and click on the Connect button.

how to connect to vm in azure

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

azure vm access

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

access 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.

1. Search for “mstsc” in your local machine. You will find the “Remote Desktop Connection” app. Click on that.

how to access vm in azure

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

how to connect vm in azure

3. Enter your credentials to log in to the virtual machine in the Windows security window. Click on OK.

azure connect to vm

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

how to open vm in azure

Allowing External RDP To Your Azure VM

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

Multiple ways exist 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 select the ports you want to allow your Azure VM to connect.

how to connect azure virtual machine

Edit the Network Security Group for an existing VM

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

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

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

The other options should be based on your requirements.

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

Connect to Azure virtual machine from Windows

You can access the Azure virtual machine from the widows.

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. As you can see, the Enable Remote Desktop option is off now for me. So need to make it On first.

how to connect to azure virtual machine from windows 10

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

connect azure vm

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

To connect the virtual machine from the Windows machine locally via RDP, you can follow the steps below.

1. First, if you don’t know the public IP of your virtual machine, log in to the Azure portal, search for your virtual machine, 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”.

connecting to azure vm

2. Now search for “mstsc” on your local machine. You will find the “Remote Desktop Connection” app. click on that.

how to connect to an azure vm

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

4. Enter your credentials to log in to the virtual machine.

connect to azure vm from local machine

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

how to use azure vm

Access Azure Virtual Machine using Azure Active Directory Authentication (Preview)

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

Prerequisites

As a prerequisite, you must note that the Azure virtual machine must run 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 control and enforce policies for your Azure Virtual Machine centrally.
  2. You can utilize the Azure AD credentials that you have.
  3. Since you are using your Azure AD credentials, there is 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 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

Enable the Azure AD authentication option 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 click on the search result Virtual machines.
  3. On the virtual machines page, click the + Add dropdown and then click the + Virtual Machine option to create a virtual machine.
  4. On the Basic tab, Fill out all the mandatory fields and 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 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 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 the Identity section.

7. Provide the value for all the mandatory options and then click 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.

Enable the Azure AD login while creating a Virtual Machine using Azure CLI

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 connect your Azure Linux VM using the SSH key from Azure CLI or the command prompt. The cmdlet to connect the Azure Linux VM is as below

$ ssh -i <private key path> azureuser@<Public IP>

Additional Options: Securely Connect To Your Azure Virtual Machines

It’s essential to connect to your Azure Virtual Machine very securely. Security matters a lot while accessing your Azure Virtual Machines. Luckily, multiple options can help you to access your Azure VMs securely without any issues. Let’s discuss all the options here.

Just-in-time VM access

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

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

Advantage: It provides high security and reduces the risk of any malicious attack by opening the port only when needed and immediately closing it once your work is done.

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

RDP using a Private IP address with Site to Site VPN

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

If you don’t need the public IP address, 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 Jump host solution to reduce the risk of exposing all your Virtual machines to the public internet. This creates a single Virtual machine, known as jumphost, and From this box, you can connect to your other Virtual machines in your Network.

It’s pretty easy to deploy the Jumphost and provides 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 usually uses browser-based HTTP connectivity, and since it does not use the Public IP address, it is 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 without needing a Public IP address. You don’t need additional software to connect to the Azure Virtual machine.

Advantage: One of the most significant advantages is that we don’t need the Public IP to connect to the Azure VM, So it’s more secure than the other methods.

Disadvantage: It is pretty challenging to find and is not available for all the regions and is available for limited regions.

You may like the following Azure tutorials:

Conclusion

In this Azure tutorial, We discussed how to connect to a VM in Azure. Now it’s your turn to access your Azure VM (Virtual Machine) using the above information mentioned in this article !!!