Hello @SoftComm SDC ,
Thank you for reaching out to Microsoft QnA. I would like to add to what @Ronen Ariely has already mentioned.
Firstly, please confirm if you are able to login to the VM via serial console, because I have observed the the 'Connection refused' error is thrown mostly when there is a network issue. Then try the following steps depending on the individual possibilities..
1. If SSH daemon inactive/dead
Check the status of ssh daemon by running the following command systemctl status sshd. If you see that the service is inactive, you can run systemctl start sshd to start the service back again and then try to ssh into the VM. In case serial console is not working, you can check for the status of ssh daemon via Run command from the Portal on the VM blade by running the same commands as I mentioned above.
Again, login via serial console. Then check "systemctl status sshd". The service will be up and running. Open the sshd configuration file with an editor.
vi /etc/ssh/sshd_config , here check for the line containing the port and verify if you are using the same port or not for ssh.
3. Corruption of sshd_config file
Login via serial console, and check the status of ssh daemon. If you find the daemon in failed state, and even starting/restarting of the ssh service fails, then check the sshd_config file for any incorrect changes or corruption. Then, compare it with the config file of a working VM. Take a backup of the existing config file, remove the lines which appear to be incorrect and then try to restart the ssh service once the rectifications are done.
4. Iptable rules blocking SSH connection
Check for any iptable rule that might block he incoming SSH connection.
In a completely different scenario, if you see the the VM's OS in an unhealthy state, then you will have to troubleshoot that accordingly. You will be able to figure the OS health by check the latest 'Boot diagnostics' screenshot/log. If you see that the OS is waiting at the login prompt, it means OS is healthy, however if you see some kernel errors it will indicate OS being in an unhealthy state.
Now another important concept is that, it is not necessary that if the VM agent status is not ready, you will not be able to SSH into the VM. You should be able to SSH into your VM even if the Agent status is not ready because the Agent depends on other components.
To understand and troubleshoot Linux VM Agent related issues, please refer to the below links:
https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/agent-linux
https://github.com/Azure/WALinuxAgent
I hope this helps.
-----------------------
Please don't forget to Accept as Answer and Upvote and if you think my response was helpful.