DEV Community

Cover image for How to Create and Connect to a Linux VM Using a Public Key
Florence Enenmo
Florence Enenmo

Posted on

1

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

Using SSH keys, creating and connecting to a Linux VM ensures a secure and password-less login. Below is a step-by-step guide to help you set up and connect to a Linux VM using a public key.

Create a Linux VM on Azure

Login to Azure Portal

Click on *"Create a resource"
*

Image description

Click on "Virtual machine"

Image description

Configure Basic Settings:

Subscription: Select your subscription.

Resource Group: Create a new resource group or use an existing one.

Image description

Virtual Machine Name: Enter a name for your VM.

Image description

Region: Select your preferred region.

Image description

Image: Ensure "Ubuntu Server" is selected.

Image description

Size: Choose an appropriate size for your VM.

Administrator Account:

Authentication Type: Select "SSH public key".

Image description

Username: Enter a username of your choice.

Image description

SSH Public Key Source: Select "Generate new key pair".

Image description

SSH Key Type: Select "RSA SSH Format".

Image description

Select inbound ports: Select "HTTP(80), SSH(22)".

Image description

Disks: Configure the disk settings as needed.

Image description

Networking: Configure network settings

Image description

Management, Advanced, and Tags: Configure additional settings if needed. Leave at default for beginner learning.

Review + Create: Review your settings and click "Create".

Image description

Connect to Your Azure VM

Download private key:

Image description

Deployment in progress

Image description

When "Deployment is complete" Select "Go to resource".

Image description

Retrieve Public IP Address:

Go to the "Virtual Machines" section in the Azure portal.
Select your VM.
Copy the public IP address of your VM.

Connect Using SSH:

Open Terminal (Linux/Mac) or PowerShell (Windows) and connect to your VM using the private key.

Image description

Image description

Install web server:

Image description

*View of the web server:
*

Image description

Troubleshooting Tips
Permission Denied (Publickey): Ensure the public key is correctly added during VM creation and the username is correct.

File Not Accessible: Verify the file path and permissions of your private key.

Connection Issues: Ensure the network security group (NSG) rules allow inbound traffic on port 22.

Conclusion
Using SSH keys for authentication enhances the security of your connections to Linux VMs. By following these steps, you can easily create and connect to a Linux VM using a public key on Azure, ensuring a secure and password-less login.

Billboard image

The fastest way to detect downtimes

Join Vercel, CrowdStrike, and thousands of other teams that trust Checkly to streamline monitoring.

Get started now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay