DEV Community

Okechukwu Udensi
Okechukwu Udensi

Posted on

How to Create and Connect to a Linux VM using a Public Key

Table of Contents

Introduction
Step 1. Login to Azure Portal
Step 2. Select/click Virtual Machine
Step 3. Create Azure Virtual Machine
Step 4. Basic Tab: Create new Resource Group
Step 5. Basic Tab: Fill all the Virtual Machine Instance Details
Step 6. Disk Tab: Fill all the Disk fields
Step 7. Validation Passed then Click Create
Step 8. Create the Linux VM
Step 9. Open Command Prompt and run some command lines
Step 10. Run IP address on browser

Introduction
Virtual Machine is one of the resources Azure has, to help organizations and individuals execute various tasks without accessing a local computer. It simply means, having a full computer system running in the cloud with lots of advantages than carrying or stationing a physical computer system.

Connecting a Virtual Machine using SSH Public Key makes it a more secured way of connection. This helps to make a connection via command lines, run commands through your terminals to talk to server and client.

Step 1. Login to Azure Portal
Open a browser, type url: portal.azure.com
Fill in your registered username and password, then process your entries. A successful login lands into Azure portal where various tasks can be executed accordingly. Also make sure you have a subscription in Azure to enable the creation of VM.

Image description

Step 2. Select/click Virtual Machine
There are 3 ways to locate Virtual Machine in the portal (via search bar/resource group/portal tab). Go to the search bar type in virtual machine, select Virtual Machine from the dropdown list.

Image description

Step 3. Create Azure Virtual Machine
Locate the create button up left, click Connect from the dropdown.

Image description

Step 4. Basic Tab: Create new Resource Group

Notice: There is a note on how each instance field works. This icon is found suffix each field label. Take a cursor point to the icon, then read. Also all red asterixis label field are compulsory and must be filled.

Select from already created resource group or create new one if none exists. Click New and type in the new resource group name, click ok.

Image description

Step 5. Basic Tab: Fill all the Virtual Machine Instance Details

  • Virtual Machine Name: Valid name could contain alpha-numeric, alpha + some special characters excluding underscore (_). Eg. Denz-VM, Denz4 etc
  • Region: Select from the dropdown according to your architectural plan.

Step 6. Disk Tab: Fill all the Disk fields

  • Region: Select a desired data center region
  • Availability options: Select how you want your availability zone to run (eg. no infrastructural redundancy required etc.)
  • Availability zone: Select your zone(s) or
  • Security type: Select how you want to secure the VM. Eg. Standard
  • Image: Select either Linux type of OS (e.g Ubuntu Server 24.04LTS x64)

Image description

  • VM architecture: Could be on x64
  • Size: Select from the dropdown as it is available in the regional zone selected.
  • Enable Hibernation: Check if you want otherwise ignore Administrator account Because Linux image was selected instead of Windows, the Authentication type will show these options --SSH Public Key -- Password Here we are selecting SSH Public Key.
  • Username: Type in your username
  • SSH public key source: You have options to Generate a new key or Use the existing key. (Select Generate new Key Pair).
  • SSH Key Type: Checkbox: RSA SSH Format
  • Key pair name: This key is automatically generated using the inputted VM name and must be kept safe because without this key your connection to VM will be aborted.

Image description

  • Public inbound ports: Allow selected ports
  • Select inbound ports: Select how you want the VM to be accessed. Eg. HTTP(80), SSH(22)
  • Click on Next Disk button to proceed to the next tab set-up.

Note:
You can leave every other field in this Tab at default then proceed.

Image description

For now, accept Networking, Monitoring, Advance and Tags Tabs at default level. Click Review and Create Button.

Step 7. Validation Passed then Click Create
At this point the information inputted on the Tabs are reviewed for validation. Most especially make sure you have a strong internet connection in order to experience smooth loadings.

Image description

Step 8. Create the Linux VM
Once you click on create button, it will prompt you to download a private key file which must be done if not you will not find it again. Click "Download private key and create resource", automatically the file will be downloaded into your download folder.

Image description

Image description

Image description

Step 9. Open Command Prompt and run some command lines
Here you type in "command prompt" in the search field of your task bar, select run as administrator.

Image description

To copy private key file path, open the download folder, click on the file once to select the file, click inside the address bar and copy the highlighted folder path (eg. C:\Users\dell\Downloads)

Combine and type these 3 things inside the command prompt:

  1. ssh -i
  2. C:\Users\dell\Downloads\DezxLVM_key.pem
  3. DezAzure@20.160.81.95 (this is your Linux VM username@Ip address)

Image description
ssh -i C:\Users\dell\Downloads\DezxLVM_key.pem DezAzure@20.160.81.95

Hit enter button on your keyboard and type yes to process further.

Image description

type in: sudo apt-get -y update
Hit enter key to process further
DezAzure@DezxLVM:~$ sudo apt-get -y update

Image description

type in: sudo apt-get -y install nginx
Hit enter key to process further

Image description

Step 10. Run IP address on browser
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.
Image description

Top comments (0)