Azure

Create a Secured Shell (SSH) key pair in Azure

Create a Secured Shell (SSH) key pair in Azure

About Secured Shell (SSH):

  • It is an encrypted connection protocol, therefore, protects the communication security and integrity
  • It allows secure and strong connection over an unsecured connection
  • It helps to eliminate the requirement of password for the sign-in process, but it shares the private key
  • It is default connection protocol for Linux virtual machines hosted on Microsoft Azure
  • Mainly used for secure remote login from one computer to another computer.

How do SSH works?

Thus, SSH follows the client-server model so the request goes from SSH client to SSH server via a secure channel. The SSH uses public-key cryptography to get it verified on the SSH server.

Image resource: ssh.com

Pre-requisites:

Original syntax:

Open the Azure Portal and click on the Shell icon [>_]

Steps:

Enter the command on Bash prompt

abhishek@Azure:~/.ssh$ ssh-keygen -t rsa -b 2048 -C "admin@myserver"

It will ask for the file name to store the key files

Enter file in which to save the key (/home/abhishek/.ssh/id_rsa): sshdemo

Then, it would ask for the passphrase (password to access the private key file). This should be remembered to the originator for future reference.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in sshdemo.

Finally, the keys will be generated with the <filename.pub> and you will get the below message along with the key fingerprint which is an encrypted format of the key

Your public key has been saved in sshdemo.pub.

The key fingerprint is:

SHA256:Y0UchcjQ1sVqzbe3VlB7nBLw4Ur3MXqtLC9tPt8c/VM admin@myserver

You also can generate the ssh keys at the time of creating Linux virtual machine through Azure CLI. The following command can be used:

az vm create --name VMname --resource-group RGname --generate-ssh-keys

The --generate-ssh-keys flag will create the ssh keys at runtime.

Note: the default location for key files is ~/.ssh directory unless specified. You can use

–ssh-dest-key-path flag to give the custom path.

Abhishek Maitrey

With over 15 years of IT experience in various renowned MNCs like Wipro Technologies, Cognizant Technology Solutions (CTS), etc Abhishek is one of the active members of C-Sharpcorner events, NCR Xamarin Developers group and Agile Meetups. He has worn the hats of different roles during his corporate tenure and currently works as Applications Development/Support manager in an MNC in Noida, still, he calls himself as a developer by passion. Along with technical knowledge of Microsoft Azure DevOps, ASP.Net Core, C#, ASP.Net, Angular, etc. He is also well versed in project management verticals like ITIL processes and Agile/Scrum methodology. A happy husband and father of two lovely kids. He likes the association of professionals, leadership, public speaking. Reach out him by [email protected] or follow on twitter: @abhimaitrey