HOW TO CREAT AND CONNECT TO A LINUS VM USING A PUBLIC KEY.
Published: 2024-06-21 06:46:13

Here are the steps to creating and connecting to Linus VM using a public key.

_Sign in to Azure
Create a Resource Group
Create SSH Public Private Key Pair
Create Virtual Machine
Connect to Virtual Machine.

**SIGN IN TO AZURE**
To sign to Azure. Type in "portal.azure" on the web browser to open the Azure portal. Enter your email and password on the login page, and sign in.

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

**CREATE A RESOURCE GROUP OR USE AN EXISTING RESOURCE GROUP**
To create a Resource: on the search bar, type in virtual machine. Select virtual machine from the dropdown. 

Then click on 'Create' and select Azure Virtual Machine. 

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


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

From the "Create a Virtual Machine" page, create a new Resource Group or select from an existing resource group.

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

**CONFIGURE BASICS**
_Choose a VM name
Region
Availability Option
Security Type_
_Image_. This refers to the OS. In this case, we are working with Linus OS
Size


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

**CREATE SSH PUBLIC KEY**
"Administrator Account"
For _Authentication type_ under "Administrator Account"; select SSH Public Key.
Azure automatically generates an SSH Key Pair and allows you to store it for future use. It is a fast, simple, and secure way to connect to your VM.

_Username_. A default username is created, this can also be changed.

_SSH Public Key Source_. A new Key Pair is generated by default. If you already have an existing key pair; select any other suitable option from the dropdown bar.

_SSH Key Type_. Select RSA SSH format.

_Key Pair Name_. Automatically named. It is named after the VM with _key (underscore key) added at the end as a "suffix".

**Inbound Port Rules**
_Public Inbound Ports_. Allow Selected Ports is selected.

_Select Inbound Ports_. HTTP(80), and SSH(22)

See attached screenshot


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6493sto2o60sp1up4np7.PNG)

Since we are creating a simple Linus VM; the settings for Disks, Networking, Management, Advance, and Tags will remain at default.
We can go ahead and click "Review and Create". In the future, if and when the need arises; the default settings can be changed in the VM's settings.

After clicking 'Review and Create'; the validation page will come up. See below screenshot

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

We can then proceed to create the VM by clicking create at the bottom of the page. 

A prompt will pop up requesting a download of the Private Key as shown in the screenshot below. Click download and wait while it downloads and deploys. This might take a while, it is downloaded automatically to the download folder


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

After deployment is completed, click on Go To Resource.


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

After clicking on 'go to resource', the overview page of the Linux VM will open.

**CONNECT TO THE VM**
To connect to the VM, open cmd or powershell. Then, type in ssh -i "the path of the downloaded key pair,the generated key pair name.pem" azureusername@ip address and press enter. The screenshot below shows connection to the VM was successful.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/31v6w6ie1za26fxmfcoh.PNG)

After successfully connecting to the VM, you can then, go ahead and install web server and connect to nginx by running sudo commands.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8nrf1kgzy87ny7b1it38.PNG)


Since this VM is for test purposes; it is important not to leaves the resources running as the idle resources will be incurring costs. It is advisable that we delete the resources.