An Azure service that is used to provision Windows and Linux virtual machines.
Quick troubleshooting steps
After each troubleshooting step, try reconnecting to the VM.
Reset the credentials for the user.
Verify the network security group rules permit SSH traffic and role assignment.
Ensure that a Network Security Group rule exists to permit SSH traffic (by default, TCP port 22).
You cannot use port redirection / mapping without using an Azure load balancer.
If you are using Microsoft Entra ID to manage SSH logins, the user must be assigned the Virtual Machine Administrator Login or Virtual Machine User Login role on the resource group that contains the VM and its associated resources. Otherwise, the "Permission denied (publickey)" error will be received. For more information, see Configure role assignments for the VM that uses Microsoft Entra login.
Check the VM resource health.
Ensure that the VM reports as being healthy.
If you have boot diagnostics enabled, verify the VM is not reporting boot errors in the logs.
Continue reading for more detailed troubleshooting steps and explanations.
Available methods to troubleshoot SSH connection issues
You can reset credentials, SSH configuration, or troubleshoot the status of the SSH service by using one of the following methods:
Azure portal - great if you need to quickly reset the SSH configuration or SSH key and you don't have the Azure tools installed.
Azure VM Serial Console - the VM serial console will work regardless of the SSH configuration, and will provide you with an interactive console to your VM. In fact, "can't SSH" situations are specifically what the serial console was designed to help solve. More details below.
Use Run Command through Azure portal - You can run basic commands by using the Run Command functionality through the Azure portal. The output will be returned to the portal.
Azure CLI - if you are already on the command line, quickly reset the SSH configuration or credentials.
Azure VMAccessForLinux extension - create and reuse json definition files to reset the SSH configuration or user credentials.
After each troubleshooting step, try connecting to your VM again. If you still cannot connect, try the next step.
If you are still unable to SSH to your VM after following the after steps, see more detailed troubleshooting steps to review additional steps to resolve your issue.
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin