An Azure service that is used to provision Windows and Linux virtual machines.
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:
- 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.
- 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.
- On the same Reset password blade:
- 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.
- 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
- Script to fix common “permissions too open” issues (replace
- 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
- RHEL:
- 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)"
- Reset SSH configuration (replace resource group and VM name):
- 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:
- Troubleshoot SSH connections to an Azure Linux VM that fails, errors out, or is refused
- Troubleshoot SSH connection issues in Azure Linux VM due to permission and ownership issues
- Can't SSH to Azure Linux VM because permissions are too open
- SSH connection to Azure Linux virtual machines fails due to SELinux misconfiguration