Cannot SSH to VM though the VM is Running.

Anonymous
2026-06-25T07:00:09.03+00:00

The VM is running, Agent Status is "Not Ready" and I cannot SSH to the VM. Tried "Run Command", "Reset Password", "Serial Console" options but no help.

Azure Virtual Machines
Azure Virtual Machines

An Azure service that is used to provision Windows and Linux virtual machines.

0 comments No comments

1 answer

Sort by: Most helpful
  1. AI answer

    2026-06-25T07:00:27.1633333+00:00

    Since the VM is running but the Azure VM Agent shows Not Ready, and SSH plus Run Command and Serial Console are failing, focus on SSH configuration and permissions from the guest side using the available methods.

    Follow these steps in order and test SSH after each change:

    1. Reset SSH configuration from Azure portal
      • In Azure portal, open the VM.
      • Scroll to the Help section and select Reset password.
      • In Mode, choose Reset configuration only.
      • Select Update, wait for completion, then try SSH again.
    2. Reset SSH credentials from Azure portal
      • On the same Reset password blade:
        • Choose Reset SSH public key or Reset password.
        • Enter the existing username and a new key or password, or create a new user with sudo privileges.
      • Select Update, then try SSH with the new credentials.
    3. Verify NSG and routing for SSH
      • Ensure an inbound Allow rule exists for TCP port 22 on the VM’s NIC/subnet NSG and that no higher-priority Deny rule blocks it.
      • Use IP flow verify in Network Watcher to confirm SSH traffic is not blocked.
      • Use Next hop and effective routes to confirm traffic is correctly routed to the VM.
    4. Repair SSH permissions if they were changed
      If SSH configuration or home directory permissions were modified, restore them using either Serial Console (if it works intermittently) or Run Command when the agent is responsive:
      • Script to fix common “permissions too open” issues (replace <username>):
             chmod -R 644 /etc/ssh
             chmod 600 /etc/ssh/ssh_host*key
             chmod 600 /etc/ssh/sshd_config
             chmod 755 /home/<username>
             chmod 700 /home/<username>/.ssh
             chmod 600 /home/<username>/.ssh/authorized_keys
             cd /home
             chown <username> <username>
        
      • After running this via Serial Console or Run Command, restart sshd:
             systemctl restart sshd
        
    5. Fix known directory ownership issues by distro (if applicable)
      If the VM boots but SSH fails due to specific directory ownership problems, use Serial Console or Run Command with the appropriate commands:
      • RHEL:
             sudo mkdir -p /var/empty/sshd
             sudo chmod 755 /var/empty/sshd
             sudo chown root:root /var/empty/sshd
        
      • SUSE:
             sudo mkdir -p /var/lib/empty
             sudo chmod 755 /var/lib/empty
             sudo chown root:root /var/lib/empty
        
      • Ubuntu:
             sudo mkdir -p /var/run/sshd
             sudo chmod 755 /var/run/sshd
             sudo chown root:root /var/run/sshd
        
    6. Use Azure CLI if portal-based reset is not effective
      When CLI access to the subscription is available, reset SSH from the command line without changing users or keys:
      • Reset SSH configuration (replace resource group and VM name):
             az vm user reset-ssh --resource-group myResourceGroup --name myVM
        
      • If needed, reset a user’s password:
             az vm user update --resource-group myResourceGroup --name myVM \
                  --username myUsername --password myPassword
        
      • Or reset the SSH public key:
             az vm user update --resource-group myResourceGroup --name myVM \
                 --username myUsername --ssh-key-value "$(cat ~/.ssh/id_rsa.pub)"
        
    7. Check VM health and redeploy if necessary
      • Verify VM resource health and boot diagnostics to ensure the OS is healthy and not stuck at boot.
      • If the VM is healthy but SSH still fails after configuration and permission repair, restart the VM, and if needed, redeploy it so Azure moves it to new hardware while preserving disks and configuration.

    If the VM Agent remains Not Ready, Run Command will be unreliable; prioritize Serial Console and portal/CLI-based SSH resets plus NSG/routing checks until the guest OS and agent are healthy.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.