Connect to a Virtual Machine in Azure
This article explains how to connect to a virtual machine (VM) that you've created in Azure. Depending on your VM's operating system and configuration, you can connect using Remote Desktop Protocol (RDP) for Windows VMs or Secure Shell (SSH) for Linux VMs.
Connecting to Windows VMs
To connect to a Windows VM, you'll typically use a Remote Desktop Connection (RDP) client.
Using the Azure Portal
- Navigate to the Azure portal at portal.azure.com.
- Search for and select "Virtual machines".
- Select the Windows VM you want to connect to.
- In the VM's Overview page, select the Connect button.
- Choose RDP.
- Download the RDP file.
- Open the downloaded RDP file and connect using the VM's administrator credentials.
Using RDP Client Directly
- Find the public IP address of your VM. You can find this on the VM's Overview page in the Azure portal.
- Open the Remote Desktop Connection client on your local computer (search for "Remote Desktop Connection" or run
mstsc.exe
). - Enter the public IP address of your VM and click Connect.
- When prompted for credentials, select More choices, then Use a different account. Enter the username and password you specified when creating the VM.
- You might see a certificate warning. Click Yes to continue.
Note: Ensure that port 3389 (the default RDP port) is open in your VM's network security group (NSG) and that you have a valid username and password.
Connecting to Linux VMs
To connect to a Linux VM, you'll use SSH.
Using SSH with a Password
- Find the public IP address of your Linux VM in the Azure portal.
- Open a terminal or SSH client on your local computer.
- Use the following command, replacing
<username>
with your VM's username and<public-ip-address>
with the VM's public IP address:ssh <username>@<public-ip-address>
- If prompted to continue connecting, type
yes
and press Enter. - Enter your VM's password when prompted.
Using SSH with SSH Keys
SSH keys provide a more secure way to connect.
- Ensure you have your private SSH key file (e.g.,
id_rsa
). - Open a terminal or SSH client.
- Use the following command, specifying the path to your private key:
ssh -i /path/to/your/private/key <username>@<public-ip-address>
- If prompted to continue connecting, type
yes
and press Enter.
Tip: If you are using the Azure CLI, you can often use the command
az vm show --resource-group <your-resource-group> --name <your-vm-name> --show-details --query publicIps -o tsv
to get the public IP address.
Important: Always ensure your SSH port (default 22) is open in your VM's network security group (NSG) and that your firewall rules are correctly configured.
Troubleshooting Connection Issues
- Check NSG Rules: Verify that inbound rules for RDP (3389) or SSH (22) are allowed from your IP address or a range that includes it.
- Verify VM Status: Ensure your VM is running and has successfully completed its boot process.
- Public IP Address: Confirm you are using the correct public IP address for your VM.
- Credentials: Double-check your username and password or SSH key.
- Firewall: If you have a firewall configured on the VM itself, ensure it allows inbound connections on the relevant ports.