Monday, June 22, 2015

Cant SSH to Linux VM - Azure



Did you encounter that the SSH connection is suddenly not working with Azure Linux machine.
This happens to me quit a lot with Azure Ubuntu VM. and there were not much help in the internet about this and had to call the Microsoft support,
This are the steps what we have done to resolve this issue.

  • First we can try to reset the remote session form the portal.
  • Log in to https://portal.azure.com/
  • Then go to Browse All and select Virtual Machines.
 
  • Then select the vm and  click Reset Remote Access.
 
  • If this didn't work ( in my case this didn't work) there is a script to run.
  • Open  Microsoft Azure Command Shell
  • Then first remove the All the saved azure accounts form the computer.
 # Get-AzureAccount | %{Remove-AzureAccount -Name $_.Id} Clear-AzureProfile
  • Add the Azure account to Powershell.
# Add-azureaccount
  • Then run the following script to reset the SSH
  • Replace the  red colourd with the details of the your Azure VM
$subname = "Subscription name"     #Set subscription details
$subid = "Subscription id"         #Subscription id

Set-AzureSubscription -SubscriptionName $subname
Select-AzureSubscription -SubscriptionName $subname
Get-AzureSubscription

#Sample script to reset the SSH configuration on your VM
#Identify the VM

$vm = Get-AzureVM -ServiceName 'CLOUD_SERVICE_NAME_WITHOUT_cloudapp.net'  ' -Name 'VM_Name'
##Get-AzureVMExtension -VM $Vm | Select ExtensionName, Publisher, Version
$vm.GetInstance().ProvisionGuestAgent = $true
Get-AzureVMExtension -VM $Vm | Select ExtensionName, Publisher, Version
#Set-AzureVMExtension -ExtensionName 'CustomScriptForLinux' -VM $vm -Publisher 'Microsoft.OSTCExtensions' -Version '1.2' | Update-AzureVM -Verbose
$TimeStamp = (Get-Date).Ticks

$PrivateConfig = '{"reset_ssh": "True", "timestamp": "' + $TimeStamp + '"}'

# Begin execution
$ExtensionName = 'VMAccessForLinux'
$Publisher = 'Microsoft.OSTCExtensions'
$Version =  '1.*'
Set-AzureVMExtension -ExtensionName $ExtensionName -VM  $vm -Publisher $Publisher -Version $Version -PrivateConfiguration $PrivateConfig | Update-AzureVM
  • Now try to log in the Azure with SSH Using the first account you used to connect to Azure. 
( eg : azureuser and the Password )

2 comments:

  1. Thanks had the same problem, however your instructions are not easy to follow for novice users like me. could you please help with a list of commands I can paste in terminal/command line?

    Thanks in advance

    ReplyDelete
  2. I mean like:
    1 : enter the following : "azure ... "
    2 : type : " "

    e.t.c thanks

    ReplyDelete