Share via

after resizing a virtual machine I cannot connect via ssh

Tucker Thames 0 Reputation points
2026-05-06T16:17:17.5466667+00:00

after resizing a virtual machine I cannot connect via ssh. I can connect via the serial console. I have tried a number of steps including redeploying and re-applying, reverting back to the old size, double checking nsg rules, opening up nsg rules temporarily to allow any source, creating a new key to ensure I am using a valid key pair, and more suggestions from co-pilot and gmeini. No matter what when I try to connect i get a Network Error: Connection timed out.

Has anyone had this issue?

Azure Virtual Machines
Azure Virtual Machines

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


2 answers

Sort by: Most helpful
  1. Nikhil Duserla 9,940 Reputation points Microsoft External Staff Moderator
    2026-05-29T11:35:18.0433333+00:00

    Hey Tucker, it’s great that you can still hit the serial console—that tells us your VM is up and SSHd is likely running, so a “Connection timed out” really points to something in the network path. Resizing sometimes leaves the NIC in a weird state. Here’s a targeted plan:

    1. Reset the NIC • CLI: az vm repair reset-nic --resource-group <RG> --name <VMName> --subscription <SubID> • Portal:
      • VM → Networking → select the NIC → IP configurations
      • Switch Private IP from Dynamic to Static (choose a free IP)
      • Let the VM restart, confirm SSH connectivity, then you can revert to Dynamic if you like
      (This reinitializes the NIC on the new host.)
    2. Run IP Flow Verify (Network Watcher) • Portal → Network Watcher → IP Flow Verify • VM: your Linux VM • Direction: Inbound, Protocol: TCP, Local port: 22, Remote IP: your client IP • This tells you if an NSG rule is blocking or allowing the traffic.
    3. Run Connection Troubleshoot (Network Watcher) • Network Watcher → Connection troubleshoot • Source: your VM, Destination: your client IP, Port 22, Protocol TCP • You’ll get a hop-by-hop path analysis and see exactly where packets drop.
    4. Check Effective Routes (Next Hop) • Network Watcher → Next hop • Select your VM’s NIC, enter your client IP as destination • Verify the next hop is “Internet” (or your expected gateway).
    5. Confirm SSHd inside the VM From the serial console or Run Command: sudo systemctl status sshd sudo ss -tlnp | grep :22 If SSHd isn’t listening, start/enable it: sudo systemctl start sshd && sudo systemctl enable sshd

    If after Step 1 SSH still times out but the NSG shows “Allow,” then we know it’s truly a NIC or routing issue. Please share the results from the IP Flow Verify and Connection Troubleshoot tools so we can pinpoint where it’s getting dropped.

    Hope this helps get you back on SSH quickly!

    Reference list

    • Reset NIC on Linux VM after resize:

    https://learn.microsoft.com/troubleshoot/azure/virtual-machines/linux/reset-network-interface-azure-linux-vm

    • Quick SSH troubleshooting:

    https://docs.microsoft.com/azure/virtual-machines/troubleshooting/troubleshoot-ssh-connection

    • IP Flow Verify overview:

    https://learn.microsoft.com/azure/network-watcher/ip-flow-verify-overview

    • Connection troubleshoot (path analysis):

    https://learn.microsoft.com/en-us/troubleshoot/azure/virtual-network/virtual-network-troubleshoot-connectivity-problem-between-vms

    • Next hop (effective routes):

    https://learn.microsoft.com/en-us/troubleshoot/azure/virtual-machines/linux/detailed-troubleshoot-ssh-connection

    • Use the Azure VM serial console:

    https://learn.microsoft.com/azure/virtual-machines/linux/serial-console#accessing-serial-console-for-linux

    Note: This content was drafted with the help of an AI system. Please verify the information before relying on it for decision-making.

    Was this answer helpful?

    0 comments No comments

  2. AI answer

    2026-05-06T16:17:31.5933333+00:00

    Resizing can expose or change underlying compute/network behavior, so focus on verifying that SSH is actually listening and reachable from inside the VM, then work outward.

    Since Serial Console works, use it (or Run Command) to run these checks and fixes:

    1. Confirm SSH service is running and listening In Serial Console:
         sudo systemctl status sshd.service
      
      If it is not active (running), start/restart it:
         sudo systemctl restart sshd.service
      
      Then verify it is listening on the expected port (usually 22):
         sudo ss --listen --tcp --process --numeric | grep sshd
      
      Expected output should show something like:
         LISTEN 0 128 0.0.0.0:22 ...
         LISTEN 0 128 [::]:22   ...
      
      If nothing is returned, SSH is not listening; reset the SSH configuration (step 3).
    2. Confirm SSH port configuration Still in Serial Console, check /etc/ssh/sshd_config:
         grep -i port /etc/ssh/sshd_config
         grep -i listen /etc/ssh/sshd_config
      
      If no non-comment Port line is present, default is port 22. If a different port is configured, ensure that is the port being used from the client and allowed in NSG.
    3. Reset SSH configuration from Azure side If SSH is not running or appears misconfigured, reset it to defaults using Azure CLI:
         az vm user reset-ssh --resource-group <yourRG> --name <yourVM>
      
      This resets SSH configuration without changing users or keys. If needed, also reset credentials/keys:
         az vm user update --resource-group <yourRG> --name <yourVM> \
             --username <user> --ssh-key-value "$(cat ~/.ssh/id_rsa.pub)"
      
      Alternatively, use the VMAccess extension with a settings.json containing:
         { "reset_ssh": true }
      
      and apply it:
         az vm extension set --resource-group <yourRG> --vm-name <yourVM> \
             --name VMAccessForLinux --publisher Microsoft.OSTCExtensions \
             --version 1.2 --settings settings.json
      
    4. Verify NSG and networking again (post-resize) After confirming SSH is listening on the VM:
      • Ensure the NIC/subnet NSG has an inbound rule allowing TCP 22 from the client IP.
      • Confirm there is no higher-priority deny rule blocking it.
      • If using a different SSH port, allow that port instead.
      • Check that the VM still has the expected public IP and that any upstream firewall allows SSH.
    5. Check VM health and restart/redeploy if needed
      • In the portal, verify Resource health is healthy and boot diagnostics show no boot errors.
      • If everything looks healthy but SSH still times out, restart the VM:
        • Portal: select the VM → Restart.
        • CLI:
                 az vm restart --resource-group <yourRG> --name <yourVM>
          
      • If the issue persists, redeploy the VM to a new node (noting ephemeral disk data loss and dynamic IP changes) using Redeploy in the portal or:
             az vm redeploy --resource-group <yourRG> --name <yourVM>
        
    6. Use Run Command if Serial Console is limited If Serial Console is restricted (for example, key-only auth issues), use Run Command in the Azure portal to run the same systemctl, ss, and grep commands non-interactively and inspect output.

    Following this sequence ensures SSH is running and listening inside the VM, correctly configured on the expected port, and reachable through Azure networking after the resize.


    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.