How to create a Linux VM and SSH into it
Published: 2022-10-28 18:52:25

Hands-On Lab on Creating the Azure VM (Linux (ubuntu 20.04)
There are 3 primary steps in creating the Azure VM (Linux (ubuntu 20.04).

1. Create virtual machine in the Azure Portal + Configurations
2. Test the Connection
3. Install Web Server & View the Web Server in Action


#1. Create virtual machine in the Azure Portal + Configurations
Go to your Azure Portal. Now, on your left-hand side, click “Virtual Machines”. If this is your first time creating VMs, then you will not see any instances running. Proceed “Create Virtual Machine”.

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


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

For “Project Details”, make sure the correct subscription is selected.

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

In administrator account, provide the admin username for the VM and Generate an SSH public key.


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

Make sure you select HTTP for web access

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

Then, I will leave the rest of the configurations by default. Proceed “Review + Create”. Wait until the deployment is successful.

Note: Make sure it passes Validation

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

Download the PEM Key.

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

Congratulations!!! You just created a Virtual Machine

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

#2. Test the Connection

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

Step 2: Specify the location of the PEM file on the <private path>
ssh -i <pem key location> azureuser@<ip address>xxxxxx.pem


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

Open your PowerShell and paste the path and enter, select yes on the prompt

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

Once in the VM.

#3. Install Web Server & View the Web Server in Action
Install Web Server & View the Web Server in Action
Type the following in the PowerShell

The first command is checking for any Ubuntu updates.
Update Ubuntu server 
sudo apt update

The second command is installing Apache with the “-y” option to skip required “Yes” prompts during the installation.

Install Apache Server
sudo apt -y install apache2

After running both commands, go over to the Azure Portal and copy out the Public IP

Note: if for some reasons you can't access the Azure Portal immediately, Type in the following commands to get the IP Address

This command is to find the public IP address you’ll want to input into your browser to verify that the installation has gone correctly. This is what the webpage should look like:

Find current IP address
curl https://ipinfo.io/ip

Now your type the IP on the browser and enter.

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

If you got the above image, congratulations, you just installed a Linux VM and also installed a Web Server.

Did you succeed or still have issues?

Comment Below!