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.
- Goto Azure portal (https://portal.azure.com/#home) then enter virtual machines in the search from the home page.
- Under Services, select Virtual machines.
- In the Virtual machines page, select Create and then Virtual machine. The Create a virtual machine page opens.
- 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.
- Under Instance details, enter the name of your Virtual machine and choose your desired region.
- 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.
- 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.
- 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"
- At this stage of learning, we should have every other thing to default. Click on "Review and Create"
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.
- Continue by clicking on the tag button. It is important to always tag accordingly for resource identification purpose, then click review and create
- 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"
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.
- 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"
When you get to this page, it means your virtual machine is ready and you need to connect to it.
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.
- Click on Select under the Native SSH box in order to SSH remotely from your local PC.
Note: ssh -i ~/.ssh/id_rsa.pem azureuser@13.69.102.132
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. :)
- In your window search bar, type Powershell then click.
- Now open the window power shell on your window system and perform az login for you to get into the CLI environment on Azure.
This will pop up on your default browser:
- Now click on your active account, then the access is granted on you CLI from PowerShell.
- Go back to PowerShell, you will discover this:
- 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.
- 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.
- Click on "enter" and answer yes to continue.
- You have successfully SSH into the Linux Virtual Machine.
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.
To be able to do this, repeat the whole process of creating a Linux VM from Step 1 to Step 6.
Then select password and enter your credentials username and password that you can remember.
- Leave other tab in default, click on the tag button to tag the resource accordingly.
4.Review and Create.
- Go to Resource
- Click Connect
At this point, The password you created when you created your username will be imputed into the private key path box.
- Confirm that the command has been adjusted as a result of the changes implemented on the private key path.
- 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.
- Copy the command: ssh -i 100%admin123 azureuser2@4.234.103.241 and Type "yes" accordingly.
- Enter Password
- Welcome, you are in already.
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)