Unable to connect to Linux VM using ssh port 22

Shashank Gupta 0 Reputation points Microsoft Employee
2023-10-08T14:56:17.1266667+00:00

I have port 22 open for ssh, but unable to connect to linux VM even after redeploy.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,285 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Jackson Martins 9,801 Reputation points MVP
    2023-10-08T19:05:34.73+00:00

    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--

    0 comments No comments

  2. Shashank Gupta 0 Reputation points Microsoft Employee
    2023-10-09T15:48:54.4+00:00

    Hi @Jackson Martins ,

    I tried your solution and after step 5, I followed this doc https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/update-linux-agent

    sudo apt-get install walinuxagent

    gives below error

    2023-10-09T15:44:57.036524Z WARNING Daemon cloud-init does not appear to be running

    2023-10-09T15:44:58.040851Z INFO Daemon Waiting for cloud-init to copy ovf-env.xml to /var/lib/waagent/ovf-env.xml [1682 retries remaining, sleeping 1s]

    2023-10-09T15:44:58.047840Z WARNING Daemon cloud-init does not appear to be running

    2023-10-09T15:44:59.052238Z INFO Daemon Waiting for cloud-init to copy ovf-env.xml to /var/lib/waagent/ovf-env.xml [1681 retries remaining, sleeping 1s]

    2023-10-09T15:44:59.059048Z WARNING Daemon cloud-init does not appear to be running

    2023-10-09T15:45:00.063131Z INFO Daemon Waiting for cloud-init to copy ovf-env.xml to /var/lib/waagent/ovf-env.xml [1680 retries remaining, sleeping 1s]

    2023-10-09T15:45:00.069698Z WARNING Daemon cloud-init does not appear to be running

    2023-10-09T15:45:01.073695Z INFO Daemon Waiting for cloud-init to copy ovf-env.xml to /var/lib/waagent/ovf-env.xml [1679 retries remaining, sleeping 1s]

    2023-10-09T15:45:01.080962Z WARNING Daemon cloud-init does not appear to be running