Tuesday, 27 December 2022

Create A Virtual Machine

 Create A Virtual Machine With Custom VM Images :

Azure Virtual Machines (VM) is one of several types of on-demand, scalable computing resources that Azure offers. Typically, you choose a VM when you need more control over the computing environment than the other choices offer. This article gives you information about what you should consider before you create a VM, how you create it, and how to connect to it.

An Azure VM gives you the flexibility of virtualization without having to buy and maintain the physical hardware that runs it. However, you still need to maintain the VM by performing tasks, such as configuring, scale-up/down the machine, and installing the software that runs on it.

Azure virtual machines can be used in various ways. Some examples are:

  • Development and test – Azure VMs offer a quick and easy way to create a computer with specific configurations required to code and test an application.
  • Applications in the cloud – Because demand for your application can fluctuate, it might make economic sense to run it on a VM in Azure. You pay for extra VMs when you need them and shut them down when you don’t.
  • Extended datacenter – Virtual machines in an Azure virtual network can easily be connected to your organization’s network.

The number of VMs that your application uses can scale up and out to whatever is required to meet your needs.

Prerequisites

  • An Azure Cloud Account ( you can learn how to create one from our previous blog here.)
  • Access to an SSH client: for this tutorial, we will be using Putty and Putty Key Generator installed on our Windows computer for accessing our Ubuntu Virtual Machine.

Creating An Ubuntu Virtual Machine

Step 1: In the Azure portal, search for Virtual Machine and select Virtual Machine.

Azure Portal

Step 2: Select Add.

VM Hub


Step 3: Enter the following values:

  1. Subscription: Select your Azure subscription.
  2. Resource group: Enter a new resource group name.
  3. Virtual Machine name: It should be a unique name throughout the Azure network.
  4. Region: Select an Azure location, such as Western India, Central US, etc.Azure VM Configuration
  5. Authentication Type: SSH Public Key
  6. SSH Public Key Source: Generate new key pair
  7. Select Inbound Ports: SSH (22), this is the port that we will be using to connect to our Virtual Ubuntu Machine.Azure_VM_configuration_pt2
  8. Select the Username and Key name as required and note them down as we will need them later.
  9. Once done, click on Next: Disks >


Step 4: Select the type of disk you want to use. Click Next.

VM disk selection


Step 5: Configure Networking

  1. Virtual Network: Create a new one or use your existing Network.
  2. Select Inbound Ports: SSH(22), This allows Port 22 to be opened in your Virtual Network for incoming traffic and will enable us to connect to our Virtual Machine inside our Virtual Network.
  3. Leave everything else as default and click next to go to the Management Section.

VM Network Configuration


Step 6: Management

Leave all options as default and click on next to go to the Advanced Section.

VM Management Configuration

Step 7: Advanced Configuration

Add any custom data you want to run when the VM is being created or leave all options as default and click on next to go to the Tags Section.

VM Advanced Configuration

Also Read: Our previous blog post on VM Scale Set Azure. Click here

Step 8: Tags Configuration

Add any descriptive tags you would like to put to identify your VM at a later stage or leave Options at default and click on next to review and create your Virtual Machine.

VM Tags Configuration

Step 9: Review your settings and make any changes if required and select Create. It takes a few seconds to create a VM.

VM review and create


Step 10: SSH Keys

  1. After you click on Create Azure will create an SSH Key Pair that we will be using to connect to our VM later. Make sure to download the private key and keep it somewhere safe.
  2. Azure does not store your private key and this is the only instance when you will be able to access your private key from Azure.

VM Private key pair

VM creation wait

VM deployment process

Deployment Completion Summary


Connecting to Ubuntu Virtual Machine

As we have configured our VM to be accessible via SSH we will be using the PuTTY SSH client on our Windows machine.

You can download and install PuTTY from its official website. Simply select Download Putty and choose the appropriate installation file (32-bit or 64-bit as per your system) from the choices shown.

PuTTY configuration

Step 1: Converting our Private key into the proper extension.

The Azure private key we downloaded is in the (.pem) format, for using it with PuTTY we need to convert it into the (.ppk) format.

  1. Open PuTTYgen, an application automatically installed alongside PuTTY.
  2. Select load an existing private key. (make sure to select All files option while browsing to your Azure Key)
  3. You will get an Operation successful message if the key was imported correctly.
  4. Click on Save Private Key to save the key in a PuTTY usable format.
  5. you can optionally set a password to be used with this key for further security but for this tutorial, we will be skipping that.

PuTTYgen configuration


Step 2: Getting the SSH connection information.

  1. Go to the VM dashboard
  2. Select your VM
  3. Note the public IP address. 

VM Public IP


Step 3: Open the PuTTY installation on your Windows Machine.

  1. Enter the Host Name details in the following format: <Username of VM>@<Public IP of VM>
  2. Make sure Port is 22.
  3. The connection type is SSH.

PuTTY VM Connection


Step 4: Inserting our SSH key for authentication.

  1. Expand the SSH option under Connection in the sidebar.
  2. Select Auth, Do not expand it.
  3. Leave all options at default settings and under private key file for authentication, browse to the Private Key we had created from PuTTYgen earlier.
  4. Click Open.
  5. Click yes in the security alert box to allow the remote connection.

VM PuTTY connection

If all the steps were done correctly then the connection will be successful and you will be logged into your Ubuntu Virtual Machine.

VM Connection Sucessfull


No comments:

Post a Comment