Connect to a Linux Virtual Machine on Azure
This tutorial guides you through connecting to a Linux virtual machine (VM) that you've deployed in Azure. We'll cover common connection methods like SSH.
Prerequisites
- An Azure account with an active subscription. If you don't have one, create a free account.
- A Linux VM deployed in Azure. If you don't have one, you can create one using the Azure portal or Azure CLI.
- Network connectivity to your Azure VM (e.g., your VM is in a virtual network that your client machine can access).
Connection Methods
1. Connecting with SSH (Secure Shell)
SSH is the standard and most secure way to connect to Linux VMs. You can use an SSH client from your local machine.
Using Azure CLI (Recommended for automation)
If you have the Azure CLI installed and logged in, you can use the following command:
az vm user show --name <YourVMName> --resource-group <YourResourceGroupName> --show-details-only
This command can provide you with the public IP address and username, which you can then use with your SSH client.
Using an SSH Client (e.g., OpenSSH, PuTTY)
Once you have the public IP address and username for your VM, you can connect using your preferred SSH client.
From a Linux, macOS, or Windows (with OpenSSH installed) terminal:
ssh <username>@<public_ip_address>
Replace <username>
with your VM's username and <public_ip_address>
with the VM's public IP address.
Using PuTTY on Windows:
- Download and install PuTTY if you haven't already.
- Open PuTTY.
- In the "Host Name (or IP address)" field, enter the public IP address of your VM.
- Ensure the "Port" is set to
22
and "Connection type" isSSH
. - Click "Open".
- You will be prompted to enter your username and password.
2. Connecting via Azure Bastion
Azure Bastion is a fully managed PaaS service that provides secure and seamless RDP/SSH access to your virtual machines directly through the Azure portal. It's an excellent choice for securing your management access.
- Navigate to your Azure Bastion resource in the Azure portal.
- Select the VM you wish to connect to.
- Click "Connect".
- Enter your VM's username and password.
- Click "Connect".
This method eliminates the need to expose RDP/SSH ports directly to the public internet.
Troubleshooting Connection Issues
- Firewall Rules: Ensure that Network Security Group (NSG) rules associated with your VM's network interface or subnet allow inbound traffic on port 22 (for SSH).
- Public IP Address: Verify that your VM has a public IP address assigned and that you are using the correct one.
- Credentials: Double-check your username and password. If using SSH keys, ensure the public key is correctly configured on the VM.
- VM Status: Confirm that your VM is running and in a healthy state.