Create and Connect to a Linux VM using a Public Key

Azure virtual machines (VMs) can be created through the Azure portal. This method provides a browser-based user interface to create VMs and their associated resources. This blog post shows you how to use the Azure portal to create a virtual machine (VM…


This content originally appeared on DEV Community and was authored by Tracy Chinedu

Azure virtual machines (VMs) can be created through the Azure portal. This method provides a browser-based user interface to create VMs and their associated resources. This blog post shows you how to use the Azure portal to create a virtual machine (VM) that runs on Linux server and connect using Powershell.

In this blog you will see how to create and connect a Linux VM using public key.Public key authentication allows you to access a server via ssh without password.

If you don't have an Azure subscription, create a free account before you begin.

Sign in to Azure
Sign in to the Azure portal.

Create virtual machine

  • Enter virtual machines in the search.

  • Under Services, select Virtual machines.

  • Subscription: Choose the appropriate subscription.

  • Resource Group: Create a new or select an existing resource group.

  • Virtual machine name: Give your VM a unique name.

  • Region: Choose the data center region of your choice, preferably a region closest to you.

  • Availability options: Select the availability preferences.

  • Choose a linux server for the Image.

Image description
Image description

  • Select size of the memory Image description

Security and Authentication

  • Authenticator type - Select SSH public key
    Azure will automatically generate an SSH key pair for you to
    store for future use. It is a fast simple and secure way to
    connect to the VM.

  • SSH Key type - Select RSA SSH Format
    Image description

  • Enter key pair name

  • Public inbound ports- Select allow selected ports

  • Select HTTP(80),SSH(22)

  • Click Review + Create

Image description

  • VM is validated and shows the costing information.
  • Select create. Image description

Download private key and create resource
Image description

Deployment is complete
-Select go to resource
Image description

VM is ready
Here we can see all the details on the VM that was just created. Copy the public IP address because we would use it to connect.
Image description

Connecting to the VM using power shell

  • Navigate to Windows Powershell on a PC.
  • Run this command the command below ssh -i "path to the private key on the pc" username@publicIP

Image description
After connecting to the VM,we run some sudo commands to test
sudo apt-get -y update
Image description

sudo apt-get -y install nginx
Image description

Testing public key on a browser
Image description

Clean Up
After creating and deploying the Vm, since this project is just for practice.We clean up by deleting the resource group to avoid incurring cost.

  • Search for resource group
  • Select the resource group that was created for this VM

Image description

  • Select all resources that were created
  • Click delete
  • Enter resource group name to confirm deletion

Image description

Conclusion
With a secure shell (SSH) key pair, you can create virtual machines (VMs) in Azure that use SSH keys for authentication. This article elaborates on how to quickly generate and use an SSH public-private key file pair for Linux VMs.


This content originally appeared on DEV Community and was authored by Tracy Chinedu


Print Share Comment Cite Upload Translate Updates
APA

Tracy Chinedu | Sciencx (2024-06-19T18:36:27+00:00) Create and Connect to a Linux VM using a Public Key. Retrieved from https://www.scien.cx/2024/06/19/create-and-connect-to-a-linux-vm-using-a-public-key/

MLA
" » Create and Connect to a Linux VM using a Public Key." Tracy Chinedu | Sciencx - Wednesday June 19, 2024, https://www.scien.cx/2024/06/19/create-and-connect-to-a-linux-vm-using-a-public-key/
HARVARD
Tracy Chinedu | Sciencx Wednesday June 19, 2024 » Create and Connect to a Linux VM using a Public Key., viewed ,<https://www.scien.cx/2024/06/19/create-and-connect-to-a-linux-vm-using-a-public-key/>
VANCOUVER
Tracy Chinedu | Sciencx - » Create and Connect to a Linux VM using a Public Key. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/06/19/create-and-connect-to-a-linux-vm-using-a-public-key/
CHICAGO
" » Create and Connect to a Linux VM using a Public Key." Tracy Chinedu | Sciencx - Accessed . https://www.scien.cx/2024/06/19/create-and-connect-to-a-linux-vm-using-a-public-key/
IEEE
" » Create and Connect to a Linux VM using a Public Key." Tracy Chinedu | Sciencx [Online]. Available: https://www.scien.cx/2024/06/19/create-and-connect-to-a-linux-vm-using-a-public-key/. [Accessed: ]
rf:citation
» Create and Connect to a Linux VM using a Public Key | Tracy Chinedu | Sciencx | https://www.scien.cx/2024/06/19/create-and-connect-to-a-linux-vm-using-a-public-key/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.