How to Set Up a Linux (Ubuntu) Virtual Machine on Azure: SSH Key vs. Password
In this article, I would give you detailed guide on how you can set up a Linux machine on Azure using the SSH key or using Password. Whichever method you choose to use to set up your Linux VM, as long as you follow these guidelines, you would get the desired outcome.
The first step would be to spin up a virtual machine. If you do not know how to spin one up, you can check my post https://hashnode.com/post/cm5wkl6r9000109mkfkp3da4v on how you can create a virtual machine.
1. SET UP WITH SSH KEY
a. Create a virtual machine and while at it, under the Administrator account, Choose SSH public key as shown in the diagram below.
b. Create a Username. Make sure not to forget the username as you would need it to connect the VM.
c. For the SSH key type, Select RSA SSH Format.
d. Key pair name would be generated automatically for you.
e. Select SSH 22 for the inbound port.
We would leave the Disks part in the default state and proceed to Networking.
f. Under Networking. all sections would be automatically programmed and named based on previous selections or names given as seen in the diagram below.
For the purpose of this guide, we would leave every other part of the creation of the virtual machine as default and proceed to Review & Create.
g. After selecting Review & Create and Validation passed, a dialog box would pop up. Select Download private key and create resource. This is the Private Key that you would be needing to enable you gain access. As for the Public key, Azure keeps that.
h. After Deployment is complete, Click on Go to Resource.
i. Select the Virtual Machine you have created, under Overview, Click Connect.
j. Click Select under Native SSH. Also take note of the Public IP address. It would come in handy when you want to connect the virtual machine.
k. After clicking Select, a dialog box comes up on the right-hand side. You have to wait a few minutes while the configuration is going on.
Once the configuration is done, part 1 would be ticked in green. You can copy the SSH to VM with specified private key format in the part 3 because that is format that we will sign in with. Finally, close the dialog box.
l. Open Terminal of Mac or Command Prompt on Windows and type this command
ssh -i (location where the private key is located on your computer) username@Public IP address. If you use a windows computer, locate the private key in your Downloads folder, right click on it and select copy as path.
m. In my case, i typed sudo ssh -i /users/megbanj/download/HonoVM_key.pem azureuser@102. 37 .158 .34
location of private key: /users/megbanj/download/HonoVM_key.pem
username: azureuser
Public IP address: 102. 37 .158 .34
I put sudo in front because I could not connect. Sudo is a command that allows users to run programs with the security privileges of another user, typically the superuser or root.
n. You would be asked to type your password. This is the password you created under the Administrator details part of spinning the virtual machine. This password will not be visible for security reasons, so you need to be careful to type the correct password.
o. After you have successfully typed your password correctly and press the Enter key, you are finally welcomed into the Linux environment.
2. SET UP WITH PASSWORD
a. Create a virtual machine and while at it, under the Administrator account, Authentication type, Choose Password as shown in the diagram below.
b. Create a Username and Password. Make sure not to forget the username and password as you would need it to connect the VM.
c. Select SSH 22 for the inbound port.
d. Click Review + Create.
e. After successful deployment, Go to Resource.
f. Select the virtual machine that has been created, Select Overview and Connect.
g. Select SSH using Azure CLI
h. The dialog box on the right side pops up. Wait for the configuration to be complete. Tick the box below the configuration details, Select Configure + Connect.
i. Click Cloud shell at the top right and the cloud shell window opens and tries to connect.
j. After Cloud Shell has opened, you will get a question if you want to continue connecting. Type Yes
k. After typing Yes, you would be in the Linux machine as shoen below
I hope you find this helpful, and I look forward to dropping more useful post as I go through this journey.
Thank.