The virtual machine must be running before using vmaccess.

How to reset password in Azure virtual machine

In this Azure tutorial, we will discuss how to fix the error the virtual machine must be running before using vmaccess. That I got while I was trying to change Azure VM Password.

The virtual machine must be running before using vmaccess.

Below are the steps that I followed to change Azure VM Password in Azure Portal, and I got this error.

You can follow the below steps to reset the password for the virtual machine

1. Login to https://portal.azure.com/

2. Search for Virtual machines there.

the virtual machine must be running before using vmaccess.

3. You will see the list of VMs created in your Azure subscription. It will show the VM name, Type, Status, ResourceGroup, Location, etc.

failed to reset password deploy failed with deployment status code (failure)

4. Now click on the VM name. “MyNewVM” in my case. You can see the details of your virtual machine like Public IP address, status, Computer name, Operating system, Size, etc.

failed to reset password deploy failed with deploymentstatuscode (failure)

5. Select the Reset Password option under support + troubleshooting from the left side menu.

failed to reset password deploy failed with deploymentstatuscode (failure)

6. As you will see in the screenshot below, the Reset password option is disabled. It does not allow me to change the password and says, “The virtual machine must be running before using VMAccess.”

deploy failed with deploymentstatuscode (failure)

This is because my VM’s status may be Stopped (deallocated) or not running. Let’s check that.

Below, the VM status is Stopped (deallocated). To fix the error “the virtual machine must be running before using vmaccess,” click the start button. After that, the VM status will be Running.

how to reset root password in azure linux vm

7. Now, if you click on the Reset Password option again, you will see that it is enabled.

Choose the Mode as Reset password.

Enter the username and password, confirm the password, and click the Update button.

azure vm change password

This is how you can reset your VM password from the Azure portal.

Change Azure VM Password using PowerShell

Well, let’s discuss how to reset Azure VM password using PowerShell.

1. First, connect to the Azure account using the below command.

Connect-AzAccount 

2. Select the Azure subscription ID

$MySubID = "<Mention Your Subscription ID>"
Select-AzSubscription -SubscriptionId $MySubID 

3. Set the Set-AzVMAccessExtension to reset the username or password.

$MyResourceGroup = "<Mention your Resource group name>" 
$MyVmName = "<Mention your VM name>" 
$MyLocation = "<Mention your VM Location>" 

Set-AzVMAccessExtension -ResourceGroupName $MyResourceGroup -Location $MyLocation -VMName $MyVmName -Credential (get-credential) -typeHandlerVersion "2.0" -Name VMAccessAgent 

Now, below is the complete Powershell script

$MySubID = "<Mention Your Subscription ID>"
$MyResourceGroup = "<Mention your Resource group name>" 
$MyVmName = "<Mention your VM name>" 
$MyLocation = "<Mention your VM Location>" 

Connect-AzAccount 
Select-AzSubscription -SubscriptionId $MySubID
Set-AzVMAccessExtension -ResourceGroupName $MyResourceGroup -Location $MyLocation -VMName $MyVmName -Credential (get-credential) -typeHandlerVersion "2.0" -Name VMAccessAgent 

Change Azure VM Password using Azure CLI

We have discussed above how to reset passwords for Azure VM using Azure Portal and PowerShell. You can also reset the password for your Azure Virtual machine using Azure CLI using the below quick steps.

  1. Open the Azure CLI from the Azure Portal.
  2. Run the below cmdlt to reset or change the password using Azure CLI.
az vm user update
 -n {Your Virtual Machine name}
 -g {Name of your resource group}
-u {Your username}
 -p {Your password}

Example:

az vm user update
 -n TSINFOVM
 -g Demo12
-u User1 -p Password@12345

If are you facing any issues while resetting the password of your Azure VM, then check out Azure VM Password Reset Not Working to get a solution.

Change / Reset Password of Virtual machine (VM) – Video Tutorial

FAQs

How To Find Azure VM Username And Password

No need to worry if you have missed your Azure virtual machine username and password. You can able to reset the username and password using the below steps:

Follow Steps 1 to 7 to reset the username and password from the “How to reset password in Azure virtual machine” section above.

You may like the following Azure tutorials:

Conclusion

In this Azure tutorial, We discussed the quick steps to change Azure VM Password. I hope you have enjoyed this article !!!