DEV Community

Cover image for Creating and Connecting to a Linux VM using a Public Key.
Ayodeji Alofun
Ayodeji Alofun

Posted on

Creating and Connecting to a Linux VM using a Public Key.

Below is a step by step guide with screenshots on how to create and connect to a Linux Virtual Machine using a public key

  • Step 1: Log into Azure Portal.
    Proceed to the Azure Portal and use your Azure account to log in.
    To create virtual machines (VMs), make sure you have the required rights and a current subscription.

  • Step 2: Type virtual machine in the search bar or click on virtual machine in the Azure services.
    search vm

  • Step 3: Click on create as shown below and select Azure Virtual Machine.
    azure vm select

  • Step 4: Select active subscription from the drop down.
    active subs select

  • Step 5: Create a new resource group and click ok or select already created one from the dropdown. For the purpose of this tutorial, we are creating a new resource group.
    create rg

  • Step 6: Create a virtual machine name.
    virtual mc name

  • Step 7: Select your desired region from the drop down.

region image

  • Step 8: Select your availability option zone from the drop down. However, for the purpose of this tutorial we choose below as shown in the image.
    availability

  • Step 9: Select your security type.
    security

  • Step 10: Select Ubuntu Servers 22.04 LTS from the image drop down or from see all images.

Ubuntu image

  • Step 11: Select x64 as VM architecture.

virtual

  • Step 12: Maintain the default setting which uncheck run with Azure Spot discount.

spot

  • Step 13: Select your preferred size.

size

  • Step 14: Maintain the default setting which uncheck enable hibernation.

hibernation

  • Step 15: Select SSH public key for Authentication type.

public key

  • Step 16: Set your username as azureuser.

azureuser

  • Step 17: Select Generate new key pair from the drop down as SSH public key source.

generate

  • Step 18: Check RSA SSH Format as your SSH Key Type.

format

  • Step 19: Input your key pair name as shown below.

key

  • Step 20: Check Allow selected ports box in the public inbound ports as shown below.

inbound port

  • Step 21: Open the drop down at Select inbound ports and check HTTP (80) and SSH (22) as shown below.

check boxes

  • Step 22: Click on Review + create as shown below to continue.

review and create

  • Step 23: A page will appear to inform you of validation progress, when validation is passed as shown below, click on create to proceed.

validation

  • Step 24: A dialogue box will appear where you will need to download the private key, ensure you note where this file is downloaded in your system.

key download

  • Step 25: Wait for few minutes and allow the deployment to initialize, submit and complete. Click on Go to resource as shown below to continue. Copy the public IP address and proceed to the next step.

Go to resources

IP add

  • Step 26: To connect, search for the command prompt, right click to run as administrator and type ssh space -i space(input file path location by right clicking on the downloaded file, click properties, security and copy the objectname path) space username(Azureuser)@public IP address and click enter to continue.

download path

command

  • Step 27: To update, run at the command prompt by typing sudo (space) apt-get (space)-y (space) update to continue.

update command

  • Step 28: To install, run at the command prompt by typing sudo (space) apt-get (space)-y (space) install (space) nginx to continue.

install

  • Step 29: Paste your IP address on the browser which will open the nginx welcome page.

welcome

Top comments (0)