Run a command in a Linux Azure VM

Here’s my scenario: I have a tomcat Ubuntu server that I wanted to log on to. Problem: can’t remember the password. Can’t actually remember the users I have created.

There are more than one solution, but here’s what I have used.

I wanted to list the existing users. An old trick from my Unix days was to dump the content of the /etc/passwd file, where you can see the usernames. Since my Azure VM has an agent, I can take advantage of the Linux Extensions and compose the following powershell:


#Enter the VM name and Service name
$vm = Get-AzureVM -ServiceName “MyServiceName” -Name “mytocam”
#Specify the command to execute
$PublicConfiguration = ‘{“commandToExecute”: “cat /etc/passwd”}’

#Deploy the extension to the VM
$ExtensionName = ‘CustomScriptForLinux’ 
$Publisher = ‘Microsoft.OSTCExtensions’ 
$Version = ‘1.*’
Set-AzureVMExtension -ExtensionName $ExtensionName -VM  $vm -Publisher $Publisher -Version $Version -PublicConfiguration $PublicConfiguration  | Update-AzureVM


Simple enough. Now you can see the results in the new and gorgeous portal:


And the results:


When I looked at the list, I even remembered that I had a specific user for monitoring that I used for SCOM. Done. I was in.

Any commands can be run this will, with full access.


Hope this helps!