Imagine having the power to spin up a Linux Virtual Machine (VM) in the cloud and securely connect to it within minutes. With Azure’s seamless integration and robust security features, creating and connecting to a Linux VM using an Azure-generated SSH key pair has never been easier. Let’s dive into the steps to get you up and running quickly!.
Step 1: Set Up Your Azure Account
Before you begin, ensure you have an Azure account. If you don’t have
- one, you can sign up for a free account here.
Step 2: Create a Linux Virtual Machine
Log In to the Azure Portal:
Go to the Azure Portal and log in with your credentials.-
Create a New Linux VM:
- Navigate to Virtual Machines: In the left-hand menu, select Virtual Machines > Create > Azure Virtual Machine.
-
Configure Basic Settings:
- Subscription: Choose your subscription.
- Resource Group: You can create a new resource group or select an existing one.
- Virtual Machine Name: Enter a name for your VM.
- Region: Select a region closest to you or your user base.
- Availability Options: Choose based on your requirements.
- Image: Select the desired Linux distribution, such as Ubuntu Server.
- Size: Choose a size based on your resource needs (e.g., Standard B1s for light workloads).
-
Administrator Account:
- Select "SSH public key" as the authentication type.
- Username: Enter your desired username.
- SSH Public Key: Click on "Generate New Key Pair". Azure will create an SSH key pair for you. The public key will be automatically added to your VM.
- Key Pair Name: Provide a name for the key pair if desired, or let Azure use a default name.
Networking: Configure your networking settings. Ensure you allow SSH (port 22) in the inbound port rules.
Review and Create: Review your configurations and click "Create". Azure will deploy your VM. It may take a few minutes to complete your deployment.
Download the private key file (.pem)
when prompted. This is essential, as you will need it to connect to the VM. Azure does not store the private key, so save it securely. Follow these steps to copy Location of the (.pem) file
Copy the name of the (.pem) file
Step 3: Find Your Public IP Address
Now that your VM is deployed, connect to it using the private key file Azure provided. So, navigate to the "Overview" section of your VM. Here, you’ll find the public IP address assigned to your Linux VM. Note this address, as you’ll need it to connect.
Step 4: Connect to Your Linux VM
Open Your Terminal:
On your local machine, open a terminal (Linux or macOS) or a PowerShell (Windows with SSH installed).Connect Using SSH:
Open your terminal and run the SSH command with the path to your private key file:
Use the following command to connect to your VM, replacing<username>
with your VM username and<public-ip>
with your VM’s public IP address:
ssh -i /path/to/your-key-name.pem <your_username>@<public_ip_address>
Replace /path/to/your-key-name.pem with the path to your downloaded .pem file.
Replace with the username you specified when creating the VM.
Replace with your VM's public IP address.
3.First-Time Connection:
The first time you connect, you may see a message asking if you want to continue connecting. Type yes
and press Enter.
4.Access Granted:
If everything is set up correctly, you should now be logged into your Linux VM.
. Congratulations! You are now connected to your Linux VM using the Azure-generated SSH key pair.
Step 5: Managing Your VM
Once connected, you can manage your VM using standard Linux commands. You can install software, configure settings, and perform administrative tasks as needed.
To run install Nginx, run these two commands
sudo apt-get -y update
and
sudo apt-get -y install nginx
Conclusion
Connecting to a Linux VM in Azure using an Azure-generated SSH key pair is a secure and efficient way to manage your cloud resources. By following the steps outlined in this guide, you can easily set up your environment and start taking advantage of the capabilities Azure has to offer. Happy cloud computing!.
Top comments (0)