How to do I create linux VM with ssh public on azure automation

Category: azure automation

Question

Ravi Gajjar on Tue, 05 Jan 2016 12:00:31


Right now, I am creating Linux VM without public key on azure automation. My aim is to create linux VM with ssh public key on azure automation. How to get ssh public key from "accets" on azure automation portal.

Also try below code:

$cert = Get-PfxCertificate -FilePath $certificate.authorized_keys
$sshKey = New-AzureSSHKey -PublicKey -Fingerprint $cert.Thumbprint   -Path  "/home/$un/.ssh/authorized_keys"

Error:

Add-AzureProvisioningConfig : Cannot bind parameter 'SSHPublicKeys'. Cannot convert the "Aazz..."


Replies

Joe Levy_ on Wed, 06 Jan 2016 21:30:16


What PowerShell script would you use to do the same in local PowerShell? Also, the full error message is not visible above.



Joe Levy
Twitter: @Jodoglevy
Blog: http://jodoglevy.com

If this post was helpful to you, please upvote it and/or mark it as an answer so others can more easily find it in the future.

Ravi Gajjar on Thu, 07 Jan 2016 07:04:06


yes, it is right but I need to create vm with ssh public key, so that how to get public key from certificate. 

Joe Levy_ on Thu, 07 Jan 2016 07:26:28


You would do so the exact same way as in local PowerShell. Ex:

 $myLxCert = New-AzureSSHKey –Fingerprint "D7BECD4D63EBAF86023BB4F1A5FBF5C2C924902A" –Path "C:\authorized_keys" 

You just need to make sure you've added the certificate to Azure before hand. Add-AzureCertificate can be used to do that. Please see https://msdn.microsoft.com/en-us/library/azure/dn495200.aspx for more info.



Joe Levy
Twitter: @Jodoglevy
Blog: http://jodoglevy.com

If this post was helpful to you, please upvote it and/or mark it as an answer so others can more easily find it in the future.

Ravi Gajjar on Thu, 07 Jan 2016 08:53:40


I want to setup the script on azure automation on portal, so that we need to get public key from certificate while is store on azure portal .

This is my workflow code on azure automation:

 ----------cut------------

$AzureConn = Get-AutomationConnection -Name $AzureConnectionName
$Certificate = Get-AutomationCertificate -Name $AzureConn.AutomationCertificateName
Set-AzureSubscription -SubscriptionName 'xxxxxxxx' -SubscriptionId   xx  -CurrentStorageAccountName 'xxxx' -Certificate $Certificate
$sshkey = New-AzureSSHKey -KeyPair -Fingerprint $Certificate.Thumbprint -Path "/home/username/.ssh/authorized_keys"

 ----------cut------------

Error :
1/7/2016 2:19:52 PM, Error: Set-AzureSubscription : ForbiddenError: The server failed to authenticate the request. Verify that the certificate is 
valid and is associated with this subscription.
At Connect-Azure:63 char:63

    + CategoryInfo          : CloseError: (:) [Set-AzureSubscription], CloudException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.SetAzureSubscriptionCommand

1/7/2016 2:19:54 PM, Error: New-AzureVMConfig : Must specify MediaLocation or set a current storage account using Set-AzureSubscription.
At Connect-Azure:65 char:65

    + CategoryInfo          : NotSpecified: (:) [New-AzureVMConfig], ArgumentException
    + FullyQualifiedErrorId : 
System.ArgumentException,Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.NewAzureVMConfigCommand