Use PowerShell to Create a Linux VM in Azure

In a couple of my previous blog articles, I’ve demonstrated how to create a storage account in Azure and how to create a reserved virtual IP address in Azure. Both of those items will be used in today’s blog article so I recommend reading through those previous blog articles if you haven’t already done so.

The goal in this blog article is to build a CentOS based OpenLogic 7.0 VM in Azure except using PowerShell instead using the Azure portal website (GUI):

azure-centos8a

First, the name of the image that Azure uses to build those VM’s will need to be determined. This can be accomplished using the Get-AzureVMImage cmdlet:

azure-centos1a

The last one in the previous set of results looks like the image that’s used to create the CentOS based OpenLogic 7.0 VM’s on Azure.

Just to be sure, let’s take a look at the details of that particular image:

azure-centos2a

Yep. That’s the image. You can also see what locations that particular image is available in as shown in the previous results.

You could also return a list of the locations where that image is available in a more readable format by selecting only the location property, splitting on the semicolon, and sorting by name:

azure-centos9a

Now to create a cloud service in Azure for our new VM:

azure-centos3a

I’ve used the process shown in this article on Azure to create SSH keys for my Linux VM. I didn’t install CYGWIN as that article suggested. I followed the process here to install and configure OpenSSL and I used Win32 OpenSSL which can be downloaded from here. I also installed Putty which the article on Azure that I previously referenced suggested.

The public key certificate that was created as shown in that previously referenced Azure article needs to be uploaded to the cloud service that was previously created. It also needs to be added to the user’s account on the Linux VM that we’ll be creating:

azure-centos4b

If you haven’t already associated a storage account with your Azure subscription, that will need to be accomplished prior to creating the VM, otherwise you’ll receive an error message stating that a default storage account hasn’t been configured or to specify a media location for the VM. This storage account must reside in the same data-center as the VM.

azure-centos5b

Create an Azure VM config using the New-AzureVMConfig cmdlet, pipe that to Add-AzureProvisioningConfig to set some of the additional options, and then pipe that to New-AzureVM to create the actual VM:

azure-centos6a

Be patient, the previous command will take a couple of minutes to complete.

I’ve opened the Putty SSH client and logged into the new VM that was created in the prevous step. I’ll verify the version of CentOS that it’s running:

azure-centos7a

If you’re looking for a client to transfer files to/from your new Linux VM, I’d recommend WinSCP. It’s easy to setup and use and it supports using certificates.

µ

Leave a Reply

%d bloggers like this: