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

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:

  1. Download and install PuTTY if you haven't already.
  2. Open PuTTY.
  3. In the "Host Name (or IP address)" field, enter the public IP address of your VM.
  4. Ensure the "Port" is set to 22 and "Connection type" is SSH.
  5. Click "Open".
  6. You will be prompted to enter your username and password.
Security Best Practice: For enhanced security, consider using SSH keys instead of passwords for authentication. You can generate an SSH key pair and configure your VM to use the public key.

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.

  1. Navigate to your Azure Bastion resource in the Azure portal.
  2. Select the VM you wish to connect to.
  3. Click "Connect".
  4. Enter your VM's username and password.
  5. Click "Connect".

This method eliminates the need to expose RDP/SSH ports directly to the public internet.

Troubleshooting Connection Issues

Tip: If you're having trouble with SSH, try connecting from a different network or checking your local firewall settings.