Hi !!
There are several issues that can prevent the connection, normally items 4 and 5 usually resolve them, so here is a systematic approach:
I Helped someone with the same problem, you can verify this here:
https://learn.microsoft.com/en-us/answers/questions/958515/vm-linux-agent-status-not-ready-unable-to-ssh-rest
1 - Check Network Configuration:
Make sure you haven't modified the default network configuration, which Azure relies on.
Check the Azure portal for any NSG (Network Security Group) rules that might be blocking traffic. Ensure SSH (port 22) is allowed.
2 - Disk Space:
Ensure that the VM hasn't run out of disk space, which can cause multiple services (including the agent) to malfunction:
df -h
3 - Firewall IPtables
Ensure your VM's firewall isn't blocking the necessary ports or IP ranges used by Azure services.
setenforce 0
iptables -L or iptables -F to clean all rules
4 - Verify the VM Agent Status:
SSH into the VM (if possible) or use Serial Console from the Azure portal to access the VM.
sudo systemctl status walinuxagent
sudo systemctl restart walinuxagent
or
5 - Try to reinstall VM agent, you can use serial console and connect to Linux directly. After connect you can run:
- systemctl stop walinuxagent
- waagent -deprovision -force
- apt-get remove --purge walinuxagent
- rm -rf /var/lib/waagent
then, install the latest package version, following the instruction from the document below:
reference: https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/update-linux-agent
Connect via serial console to fix the connection.
reference: https://learn.microsoft.com/en-us/troubleshoot/azure/virtual-machines/serial-console-linux
below article that helps you find and correct the problems that occur due to Secure Shell (SSH)
Reference: https://learn.microsoft.com/en-us/troubleshoot/azure/virtual-machines/troubleshoot-ssh-connection
Get in touch if you need more help with this issue.
--please don't forget to "[Accept the answer]" if the reply is helpful--