How to SSH into a Virtual Machine created using Azure CLI or GUI


SSH is the Acronym for Secured Shell. SSH provides the necessary credentials that can be used to connect to our virtual machines in Azure as it is a mechanism for using an encrypted connection to login into the host system remotely. It can connect to switches, routers, VMware, Linux, and any other server that supports SSH. Private and public keys are used in SSH. The public key is stored on the Linux virtual machine, while the private key is used to confirm our identity. You may build virtual machines (VMs) in Azure that employ SSH keys for authentication using a secure shell (SSH) key pair.

This article will teach you how to create and utilize an SSH public-private key file pair for Linux virtual machines fast and easily. These procedures may be completed using the Azure Cloud Shell, or a Linux VM. For the demonstrations, visual studio code was used. This article will teach you how to SSH into a virtual machine. Find similar articles here: How to Generate SSH Key in Windows 10 and how to disable RC4 Cipher Algorithms support in SSH Server also How to configure OpenSSH Server.

A virtual machine, abbreviated as VM, is similar to any other real computer, such as a laptop, smartphone, or server. It features a CPU, RAM, and disks for storing your files, as well as the ability to connect to the internet if necessary. VMs are conceived of as virtualization technology or software-defined computers within physical servers, existing solely as code, whereas the elements that make up your computer (called hardware) are actual and tangible. Here is how to install Windows Server 2019 on Virtualbox.

What is the purpose of a virtual machine?

Virtualization is the technique of establishing a software-based, or “virtual” version of a computer with a dedicated CPU, memory, and storage that is “borrowed” from a physical host machine (such as your personal computer) and/or a distant server (such as a server in a cloud provider’s datacenter). A virtual machine is a computer file (sometimes referred to as an image) that mimics the behavior of a real computer. It can operate in a distinct computing environment in a window, frequently to run a different operating system—or even to serve as the user’s whole computer experience, as is usual on many people’s work PCs. Because the virtual machine is partitioned from the rest of the system, the software running inside it cannot interact with the host computer’s principal operating system.

What are virtual machines used for?

  • Creating and deploying cloud-based apps.
  • Trying out a new operating system (OS), which may include beta versions.
  • Creating a new environment to make running dev-test scenarios easier and faster for developers.
  • Creating a backup of your current operating system.
  • Installing an earlier OS allows you to access virus-infected files or use an old program.
  • Running software or applications on operating systems for which they were not designed.

What are the advantages of utilizing virtual machines (VMs)?

While virtual machines operate the same as computers with their own installed applications, they have the advantage of being completely separate from one another and from the physical host machine. A hypervisor, or virtual machine manager, is a piece of software that allows you to run multiple operating systems on different virtual machines at the same time. This allows you to run Linux VMs on a Windows OS, or an older version of Windows on a more recent Windows OS.

Because VMs are self-contained, they’re also very portable. A VM on one hypervisor can be moved to another hypervisor on a completely different machine almost instantly.

Virtual machines have numerous advantages due to their flexibility and portability, including:

  • Financial Benefit: running several virtual environments on a single piece of technology reduces your actual infrastructure footprint dramatically. This helps you save money by reducing the number of servers you need to manage and saving on maintenance and power.
  • Precision and quickness: It’s far easier and faster to spin up a VM than it is to set up an entirely unique environment for your engineers. Virtualization speeds up the process of conducting development scenarios.
  • Reduced downtime: Because virtual machines are so portable and easy to migrate from one hypervisor to another on a separate system, they’re an excellent backup option in the event that the host goes down suddenly.

Demo: Cli vs GUI

Part 1: Deploy your Virtual Machine using Azure CLI and SSH into it

So the first thing to do would be to create a resource group and we can do this with a very easy command as shown below:

az group create --name junevm --location westus

the name of the resource group is junevm and the location we chose to have it is westus. We will be using the resource group when creating our vm if not we will get an error, which is why we needed to create it first.

resource group created
az vm create --name techdirectarchive --resource-group junevm --location westus --image ubuntuLTS --admin-user raphael --generate-ssh-key
vm is running

Things to take note of :

  1. We used the az command
  2. we gave our VM a name techdirectarchive with -name
  3. We included --resource-group in the command and used a previously created resource group junevm
  4. we added a location with –-location
  5. we added an image with the parameter --image and specified that we wanted UbuntuLTS
  6. If we are going to generate an ssh key, we need to include an admin-user we did with --admin-user raphael
  7. We added an ssh key with --generate-ssh-key

If we want to ssh into the newly created Virtual machine all we need to is: ssh admin-user@ipaddress or username@ipaddress

our admin user for the newly created vm is raphael, the ip address is shown in the

ssh raphael@

We have successfully ssh into the Virtual machine that we created using the Azure Cli command

Part 2: Deploy a Virtual Machine using Azure Portal GUI and SSH into it

We need to login into azure portal, search for VM in the search section and add the values in the box as show below:

vm details

For SSH we need to take particular note of the administrator account details. We need to favor choosing SSH public key over password as the preferred authentication. We need to choose our keypair name also make sure that our selected inbound port is ssh

admin details

We need to take note of where the keypair is downloaded to

key pair generation

After the resource is created, we need to go to the search in the overview page we look for connect as shown below:

After clicking on connect select SSH the one highlighted in green as shown in the picture above. you need to copy the command in option number 4.


let’s copy the command

ssh -i <private key path> azmoney@

The next thing to do is to search for the path to the key. And you can do this by locating the public key that was downloaded earlier. When you find it, right click on it and go to properties to show the location, you will need to append the public key name

pem key

The next thing is to determine the path to the key. You can get that by right clicking the pem file and checking the location section as shown below

path to key

The next step is to append the public key file name together with its extension to the path to key

Path to key: C:\Users\Raph\Downloads
Public key name: azmoney.pem
Final path to key : C:\Users\Raph\Downloads\azmoney.pem

SSH command we copied from Azure portal:

ssh -i <private key path> azmoney@

Our final SSH command:

ssh -i C:\Users\Raph\Downloads\azmoney.pem azmoney@

So, let’s paste this to the terminal as see if we are connected.



We were able to use Azure CLI commands to create a resource group and a virtual machine and with the format username@ipaddress we were able to SSH into the machine. We were also able to create a virtual machine from the Azure portal, in the admin section, we specified we wanted SSH as the preferred protocol, and as such, we were prompted for the download of SSH key that was later used to gain access into the VM. The steps are all shown above.

I hope you found this blog post helpful. Please let me know in the comment session if you have any questions.

Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x