Binance Exchange

Microsoft Azure Cloud: how to reset Linux Virtual Machine password from command line

If we forget the credentials to log into a Virtual Machine Linux on Azure , the Microsoft cloud platform, it is a big problem. From the Azure administraton web portal in fact, the feature that allows to reset a VM password it’s still not available and they say it will be available “soon.” To solve this problem and be able to regain access to the VM we must use the commands for resources management related to the mode used to create them: Azure Resource Manager (ARM, or the “new portal” ) or Azure Service Management , that is, the Classic or “old portal” mode.

The first thing to do then is to download the Azure Command Line Interface (CLI) installer and follow the installation procedure.

Once done, we can connect to Azure subscription using our Microsoft account, in case of personal account, or the company Azure account. To do that open a command prompt and enter the command:

azure login

The result of this command is a string containing an URL and a code necessary for authentication, as shown in the following figure:
azure login command CLI prompt

Now we need to open the browser at the given address where we’ll find a page with an input box in the upper right corner to insert the code provided by the “azure login” command. The page is shown in the following figure:
Portal for Azure authentication code insertion

After entering the code we will get the confirmation of given authorization for the device in use:
Azure authentication code inserted succesfully

In the command prompt then we will see confirmation that login to the Azure account has been successful (“login command OK”) and we will show the list of subscriptions active for the user, even with the indication of which one is set as a default subscription:

Azure CLI azure login command OK

At this point to change the login credentials we need to run the command azure vm-reset access with the following options:

  • -g RESOURCE_GROUP_NAME
  • -n VM_NAME
  • -u USERNAME
  • -p NEW_PASSWORD

So:
azure vm reset-access -g RESOURCE_GROUP_NAME -n VM_NAME -u USERNAME -p NEW_PASSWORD

If everything goes well the command returns “OK” and the password has been changed:
Azure VM reset access command OK

In some cases, the command returns a timeout error. To avoid this error it was enough to restart the VM and run the “azure vm reset-access” command immediately after the restart.

EDIT 19/07/2016: The functionality to reset password of Linux Virtual Machine is now available from the Azure web portal (do not know exactly when they enabled it, but today I saw it).

Leave a Reply

Your email address will not be published. Required fields are marked *