DEV Community

Cover image for How to Create Azure Linux VM and SSH into it.
Kehinde Oloye
Kehinde Oloye

Posted on • Updated on

How to Create Azure Linux VM and SSH into it.

I'm glad to lead you through how you can create a Linux virtual machines (VMs) on Azure and also SSH into it using Windows PowerShell.

A virtual machine is a digital emulation of a physical computer. it comes complete with a desired operating system, stores data, run programs and can connect to networks. Basically, it can do what any physical computer can do.

Azure VM can be created through the Azure portal. The Azure portal is a browser-based user interface to create Azure resources.

This quickstart shows you how to use the Azure portal to deploy a Linux virtual machine (VM) running Ubuntu Server 22.04 LTS. To see your VM in action, you have to SSH to the VM. Keeping this short and simple, follow through the following steps.

  1. Goto Azure portal (https://portal.azure.com/#home) then enter virtual machines in the search from the home page.

Image description

  1. Under Services, select Virtual machines.

Image description

  1. In the Virtual machines page, select Create and then Virtual machine. The Create a virtual machine page opens.

Image description

Image description

  1. In the Basics tab, under Project details, make sure the correct subscription is selected and then choose to Create new resource group or pick an existing one if any.

Image description

Image description

  1. Under Instance details, enter the name of your Virtual machine and choose your desired region.

Image description

  1. Choose Availability option, Security type and Ubuntu Server 22.04 LTS - Gen2 for your Image. Leave the other defaults (VM Architecture and Run with Azure Spot discount). The default size and pricing are only shown as an example. Size availability and pricing are dependent on your region and subscription.

Image description

  1. Under the "Administrative account" part, there are two types of Authentication type or methods to access the VM which are SSH public key and Password. This learning part will focus on how to access a VM with SSH public key. The second part will focus on using "a password as a means of access into the VM.

Image description

  1. Scroll down to Username and create a unique username for the VM that you could always remember. Ensure that the SSH Public key source is "Generate new key". Give a unique key pair name you could always remember. For this learning, the VM username is "azureuser" and the key pair name is "kenlinuxVM1_key"

Image description

  1. At this stage of learning, we should have every other thing to default. Click on "Review and Create"

Image description

After clicking on "Review + Create", you will wait for a few seconds till you see the caption "Validation passed" on the page. this shows that the configuration all along is valid and you can go ahead and create.

Image description

  1. Continue by clicking on the tag button. It is important to always tag accordingly for resource identification purpose, then click review and create

Image description

  1. Upon clicking on "create", the deployment of the virtual machine will start. while the deployment is ongoing, a "generate new key pair" box would pop up. Click on "download private key and create resource"

Image description

After clicking the download from the first pop-up, the VM deployment is still ongoing. you will notice another pop-up by the top right. This pop-up is to notify you that the private key with which to access your VM is being downloaded in the download folder of your computer.

Image description

Image description

  1. Upon clicking on the blue download box, you wait for some seconds until you receive a notification that your deployment is complete. Then click on "go to resource"

Image description

When you get to this page, it means your virtual machine is ready and you need to connect to it.

Image description

At this point, you have connected with your Linux Virtual Machine and it is already running. Now you need to "SSH" into the Virtual Machine and at this point.

  1. Click on Select under the Native SSH box in order to SSH remotely from your local PC.

Image description

Note: ssh -i ~/.ssh/id_rsa.pem azureuser@13.69.102.132

Image description

Now here is a twist. People don't know how to use that .pem file downloaded as generally private and public key are contained in id_rsa and id_rsa.pub files. Also when you will open that .pem file that contains --BEGIN RSA PRIVATE KEY-- AND --END RSA PRIVATE KEY--

The most important thing is that you don't need to copy rsa key between --BEGIN RSA PRIVATE KEY-- AND --END RSA PRIVATE KEY--. You just need to pass path of that .pem file in the last command listed above. Ignore other commands.

You can use powershell or Git Bash cli to SSH Linux VM but make sure to download git BASH cli then only SSH command will be supported in powershell. You you can use any other tool/cli if you want. I prefer powershell and git bash.

HERE WE GO. :)

  1. In your window search bar, type Powershell then click.

Image description

Image description

  1. Now open the window power shell on your window system and perform az login for you to get into the CLI environment on Azure.

Image description

This will pop up on your default browser:

Image description

  1. Now click on your active account, then the access is granted on you CLI from PowerShell.

You will have:
Image description

  1. Go back to PowerShell, you will discover this:

Image description

Image description

  1. The next step is to go to the download folder on your system and check out the downloaded private key that ends in ".pem" Right click on the file and click copy as path.

Image description

  1. Paste the copied private key path into the box in green, after pasting the copied key part in the private key path box, Check the red box and confirm that the command path has been adjusted accordingly. Copy the command path and run it on your Azure power shell.

Image description

Image description

  1. Click on "enter" and answer yes to continue.

Image description

  1. You have successfully SSH into the Linux Virtual Machine.

Image description

NOW: HOW TO SSH INTO LINUX VIRTUAL MACHINE BY PASSWORD.

We are now going to learn how to ssh into a Linux VM using a password.

  1. To be able to do this, repeat the whole process of creating a Linux VM from Step 1 to Step 6.

  2. Then select password and enter your credentials username and password that you can remember.

Image description

  1. Leave other tab in default, click on the tag button to tag the resource accordingly.

Image description

4.Review and Create.

Image description

Image description

  1. Go to Resource

Image description

  1. Click Connect

Image description

At this point, The password you created when you created your username will be imputed into the private key path box.

  1. Confirm that the command has been adjusted as a result of the changes implemented on the private key path.

Image description

  1. Open Powershell and perform az login accordingly. Run the copied command line part on the CLI environment in your power shell, select the active account from your default browser then go back to check the status on your PowerShell.

Image description

  1. Copy the command: ssh -i 100%admin123 azureuser2@4.234.103.241 and Type "yes" accordingly.

Image description

Image description

  1. Enter Password

Image description

  1. Welcome, you are in already.

Image description

Thanks for reading my article till the end. I hope you learned something special today. If you enjoyed this article, then please share to your friends and if you have suggestions or thoughts to share with me then please write in the comment box.

Top comments (0)