How to Create Azure Linux VM and SSH into it.
Tags: webdev, virtualmachine, azure, linux
Published: 2023-08-16 04:47:16

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kczke59vgccv0pc282og.png)

2. Under Services, select Virtual machines.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0vjcasq236zyt7rfnhjm.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wwv65q8kxzxjxankigks.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ot0ihhgo5r1jjztz53ai.png)

4. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vn27b8qnyv7ltnwzslpi.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3ii4i5gbi64j63u6il74.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uzbdrzf60is1qfudmzw7.png)

6. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7uqullrnctta9nf6n0pe.png)                                                                                                                                                                                                                                                                                                                                                                                                       

7. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rrsgbp7sz73few26lowa.png)

8. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gvehg6682cudhitayt65.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hakjcb5xtcvn7wwtbvjy.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/evxtel7ld255a6d67289.png)

10. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qzud9kz64ewh77cmt3pa.png)

11. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ma48mzzqtrcoez3i82r.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vz2cyfrtjcf06djovmw8.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lqn47g7wn12e5kmku5wu.png)

12. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eex8hqw6ga128vzy0t81.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uv7zsctlsseo2fkyw52t.png)

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.

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bttzu9i0u00lithbbmya.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c8mu4vixunffhs2zq8mj.png)

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. :)
15. In your window search bar, type Powershell then click.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gil0vc9uurnz10uie3tg.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4kguy7p5igyv78sddanc.png)

14. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h2mrun59cpkx7izjxvcy.png)

This will pop up on your default browser:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmxi3mc9vseaxzeuq0km.png)

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

You will have: 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s2q35xmnvhf95m9sgeaf.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fd4uksx7knjseox82ide.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/urwq0ual0j4s0vchrzg8.png)

17. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lx200snbf1badg1vurpf.png)

18. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gsz5x0lavpj60im16cmf.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/afc972hqblcgugt5pa1z.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ms1dsreye19rqokr5fv0.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xi91p9tpoz5isenha3c.png)


_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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljwj4m85te9ajpygwrer.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3g00iif0l06dr729192.png)

4.Review and Create.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z65skay5g7pcwz9f104d.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3fgdvgu72z31w7za1h5s.png)

5. Go to Resource

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3yy6iyuonx3qcxvuif3j.png)

6. Click Connect

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cxm4ppsisjcbzjz05pqu.png)

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

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/edsajpxk46vjx83rjann.png)

8. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8abs2y5ya2o4ryp5wq60.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4m4gtf8t6lhkvqocy41r.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2wmif10gcdgvs0hvbi56.png)

10. Enter Password

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f3tvsu2yl48akpg92ahw.png)

11. Welcome, you are in already.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6adwiq4zz2sqmdbn3n9y.png)

_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._