SSH is the Acronym for Secured Shell. SSH provides the needed credentials 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 for SSH connection.
It is worth pointing out that, Public keys are stored on the Linux virtual machine, while the private key is used for confirming our identity. You may build virtual machines (VMs) in Azure that employ SSH keys for authentication using a secure shell (SSH) key pair. In this article, you will learn how to SSH into a VM created using Azure CLI or GUI.
You will learn how to create and utilize an SSH public-private key file pair for Linux virtual machines fast and easily. These steps 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. Here are some similar guides: How to Generate SSH Key in Windows 10 and how to disable RC4 Cipher Algorithms support in SSH Server, and how to configure OpenSSH Server.
A virtual machine (VM) is similar to other real devices (laptop, smartphone, or server) on the network. 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 a technique for establishing a software-based, or “virtual” version of a computer with a dedicated CPU, memory, and storage “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.
Since virtual machines are 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, a 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.
self-contained and 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 VMthan 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 migratefrom one hypervisor to another on a separate system, they’re an excellent backup option in the event that the host goes down suddenly.
SSH into a VM created using Azure CLI or GUI
Part 1: Deploy your Virtual Machine using Azure CLI and SSH into it
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 the west. You will need to start off by using the
resource group when creating a Virtual machine. Else, we will get an error, which is why we needed to create it first.
az vm create --name techdirectarchive --resource-group junevm --location westus --image ubuntuLTS --admin-user raphael --generate-ssh-key
Things to take note of :
- We used the
- we gave our VM a name techdirectarchive with
- We included
--resource-groupin the command and used a previously created resource group
- we added a location with –
- we added an image with the parameter
--imageand specified that we wanted UbuntuLTS
- If we are going to generate an ssh key, we need to include an admin-user we did with
- We added an ssh key with
If we want to ssh into the newly created Virtual machine all we need to is: ssh
The admin user for the newly created VM is Raphael. The IP address is shown in the 22.214.171.124
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 the Azure portal, search for VM in the search section and add the values in the box as shown below:
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
We need to take note of where the keypair is downloaded to
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.
SSH into a VM created using Azure GUI
let’s copy the command
ssh -i <private key path> email@example.com
The next thing to do is to search for the path to the key. You can do this by locating the public key you 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
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
You will append the
public key file name together with its extension to the path to the key.
- Path to key:
- Public key name:
- The final path to key :
SSH into a VM created using Azure CLI
SSH command we copied from Azure portal:
ssh -i <private key path> firstname.lastname@example.org
Our final SSH command:
ssh -i C:\Users\Raph\Downloads\azmoney.pem email@example.com
Paste this command to the terminal.
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 able to create a virtual machine from the Azure portal.
In the admin section, we specified we wanted SSH as the preferred protocol, and we were prompted the download the SSH key that was later used to gain access to the VM. The steps are all shown above.
I hope you found this blog post helpful. In this guide, you have learned how to SSH into a VM created using Azure CLI or GUI. Please let me know in the comment session if you have any questions.